下面以 SecureCRT 在 Linux 下连接 Linux 服务器、使用密钥(公钥/私钥)登录 为例说明配置步骤。
在终端执行:
ssh-keygen -t rsa -b 4096
按提示操作:
~/.ssh/id_rsa生成后:
~/.ssh/id_rsa~/.ssh/id_rsa.pub在本地执行:
ssh-copy-id user@server_ip
或手动方式:
cat ~/.ssh/id_rsa.pub | ssh user@server_ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
在服务器上确保权限正确:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
File → Connect → New Session
进入:
Session Options → Connection → SSH2 → Authentication
PasswordPublicKey选择:
~/.ssh/id_rsa
如果生成时设置了 passphrase,连接时会提示输入
在服务器上编辑:
sudo vi /etc/ssh/sshd_config
修改:
PasswordAuthentication no
PubkeyAuthentication yes
重启 SSH:
sudo systemctl restart sshd
确保:
600.ssh 目录:700authorized_keys:600如遇到,可重新生成兼容格式:
ssh-keygen -m PEM -t rsa -b 4096
如果你用的是 SecureCRT 的 Windows 版 + Linux 服务器,或者想用 SecureCRT 自带的 Key Generator,我也可以分步说明。