温馨提示×

Linux SecureCRT怎么设密钥

小樊
34
2026-07-23 03:02:21
栏目: 智能运维

Linux 下使用 SecureCRT 配置 SSH 密钥登录,一般分 三步:生成密钥 → 上传公钥到服务器 → SecureCRT 使用私钥连接。下面按最常用、最稳妥的方式说明。


一、在 Linux 上生成 SSH 密钥(推荐)

1️⃣ 生成密钥对

在终端执行:

ssh-keygen -t rsa -b 4096

或(更安全):

ssh-keygen -t ed25519

按提示操作:

  • 保存路径:默认 ~/.ssh/id_rsa
  • 是否设置密码(passphrase):建议设置

生成后会有:

~/.ssh/id_rsa      # 私钥
~/.ssh/id_rsa.pub  # 公钥

二、把公钥放到服务器上

方法 1(推荐)

ssh-copy-id user@server_ip

方法 2(手动)

  1. 查看公钥内容:
cat ~/.ssh/id_rsa.pub
  1. 登录服务器,写入:
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "公钥内容" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

三、在 SecureCRT 中使用私钥

1️⃣ 下载私钥到本地(Windows)

如果你在 Windows 上运行 SecureCRT,需要把私钥拷贝到 Windows:

~/.ssh/id_rsa

例如放到:

C:\securecrt\keys\id_rsa

2️⃣ SecureCRT 配置步骤

① 打开 Session Options

Session → Properties → Connection → SSH2

② 选择 Authentication

  • 勾选 PublicKey
  • 取消 Password(可选)

③ 指定私钥

点击 Properties → Use identity file

选择私钥文件:

C:\securecrt\keys\id_rsa

✅ 如果私钥有 passphrase,连接时会提示输入


四、常见问题排查

❌ SecureCRT 提示无法加载私钥

原因:

  • 私钥格式不对(OpenSSH vs SecureCRT)

✅ 解决: 在 SecureCRT:

Tools → Convert Private Key to SecureCRT Format

转换 id_rsa.pem.pub


❌ 服务器拒绝密钥登录

检查:

ls -ld ~/.ssh
ls -l ~/.ssh/authorized_keys

权限必须:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

❌ SSH 服务未开启密钥认证

服务器检查:

grep PubkeyAuthentication /etc/ssh/sshd_config

应为:

PubkeyAuthentication yes

然后重启:

systemctl restart sshd

五、推荐配置总结

✅ 安全做法:

  • 使用 ed25519
  • 私钥加密
  • 服务器禁用 root 密码登录
  • SecureCRT 只用 PublicKey

如果你愿意,可以告诉我:

  • ✅ SecureCRT 在 Windows / Linux / macOS
  • ✅ 登录的是 本地虚拟机 / 云服务器
  • ✅ 是否使用 跳板机

我可以给你 完全对应你环境的配置步骤

0