温馨提示×

linux securecrt怎么配密钥

小樊
44
2026-10-12 12:30:27
栏目: 智能运维

下面以 SecureCRT 在 Linux 下连接 Linux 服务器、使用密钥(公钥/私钥)登录 为例说明配置步骤。


一、在本地 Linux(运行 SecureCRT 的机器)生成密钥

在终端执行:

ssh-keygen -t rsa -b 4096

按提示操作:

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

生成后:

  • 私钥:~/.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

三、在 SecureCRT 中配置使用密钥

1. 打开 SecureCRT

File → Connect → New Session

2. 配置连接

  • Protocol: SSH2
  • Hostname: 服务器 IP
  • Port: 22
  • Username: 服务器用户名

3. 配置密钥认证

进入:

Session Options → Connection → SSH2 → Authentication
  • 取消 Password
  • 勾选 PublicKey
  • 点击 Properties

选择:

  • Use identity file
  • 浏览并选择本地私钥:
    ~/.ssh/id_rsa
    

如果生成时设置了 passphrase,连接时会提示输入


四、禁用服务器密码登录(可选,增强安全)

在服务器上编辑:

sudo vi /etc/ssh/sshd_config

修改:

PasswordAuthentication no
PubkeyAuthentication yes

重启 SSH:

sudo systemctl restart sshd

五、常见问题

1. 权限错误导致无法登录

确保:

  • 本地私钥权限:600
  • 服务器 .ssh 目录:700
  • authorized_keys:600

2. SecureCRT 不支持 OpenSSH 新格式密钥

如遇到,可重新生成兼容格式:

ssh-keygen -m PEM -t rsa -b 4096

如果你用的是 SecureCRT 的 Windows 版 + Linux 服务器,或者想用 SecureCRT 自带的 Key Generator,我也可以分步说明。

0 踩