Skip to main content

openSSH

生成key​

ed25519 算法 (更快更好)​

ssh-keygen -t ed25519 -C "your_email@example.com"

rsa算法 (低版本兼容)​

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

目标主机设置 SSH​

1. 添加公钥到目标主机​

authorized_keys 的公钥可以为多个 每行为一个

cd ~/.ssh

cat id_ed25519.pub >> authorized_keys

2. 设置 sshd​


# 编辑配置文件
vim /etc/ssh/sshd_config

# 设置允许密钥认证
PubkeyAuthentication yes

# 设置 AuthorizedKeysFile
AuthorizedKeysFile .ssh/authorized_keys

# 设置 Root 仅允许密钥认证
PermitRootLogin prohibit-password

# 设置 不允许密码登陆
PasswordAuthentication no

# 设置 X11 转发
X11Forwarding yes

# 设置允许 TCP 转发(通常用于数据库链接等)
AllowTcpForwarding yes

#保存
:wq

3. 重启ssh 以应用设置​

service sshd restart

登录远程主机​

cmd​

ssh -i id_ed25519 root@target_ip

其他客户端​

导入至ssh key 在登陆的时候选择即可