下面以 Ubuntu(作为 SSH 服务端)+ SecureCRT(作为客户端) 为例,说明如何配置 密钥登录。
ssh-keygen -t rsa -b 4096
或(更推荐)
ssh-keygen -t ed25519
一路回车即可,默认生成在:
~/.ssh/id_rsa~/.ssh/id_rsa.pubcat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
id_rsa)复制到 Windowsid_rsa如果 SecureCRT 提示格式不支持,用方法二转换
在 Ubuntu 或 Windows(有 OpenSSH)执行:
ssh-keygen -p -m RFC4716 -f id_rsa
或在 Windows 用 SecureCRT 自带工具:
Tools → Convert Private Key to SecureCRT Format编辑:
sudo vim /etc/ssh/sshd_config
确保以下配置:
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no # 禁用密码(可选)
重启 SSH:
sudo systemctl restart ssh
确保:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
sudo tail -f /var/log/auth.log
如果是加密家目录,需将 authorized_keys 放到非加密路径并修改 sshd_config
如果你愿意,我可以:
你当前是 Ubuntu 桌面还是服务器?Windows 还是 Mac 用 SecureCRT?