ssh uses a key to log in to a dragon

1. Generate a key

Both windows/Linux are this command

ssh-keygen

Choose the location where the key is stored and the password according to your needs

2. Install the ssh service on the server

# 安装
sudo apt install openssh-server

# 查看状态
systemctl status sshd
# 启用状态下,显示Active: active (running)

# 如果没启用,使用命令
systemctl restart sshd

3. Send the public key to the server

ssh-copy-id -i [你的密钥地址/]id_rsa.pub  [服务端用户名]@[服务端ip]

For example ssh-copy-id -i .ssh/id_rsa.pub [email protected], modifying according to your own information

4. Modify the configuration file

# 备份配置文件,虽然改的不多
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

sudo vim /etc/ssh/sshd_config
Emphasis: The modification is /etc/ssh/sshd_config , not /etc/ssh/ssh_config . If there are too many files, don’t make mistakes
and remove the comments to ensure that these items take effect

# 开放端口
Port 22
ListenAddress 0.0.0.0
ListenAddress ::

# 关于是否放开root权限登录看自己情况
# 如果可以使用root登陆
PermitRootLogin yes

# 确认使用密钥登陆
RSAAuthentication yes
PubkeyAuthentication yes

# 禁用密码登陆
PasswordAuthentication no

Restart the service after saving and exiting
systemctl restart sshd

5. Log in again, it has taken effect

Guess you like

Origin blog.csdn.net/CSDN_Ethan2086/article/details/131763775