温馨提示×

linux securecrt怎样配密钥

小樊
48
2026-09-27 21:03:25
栏目: 智能运维

下面以 SecureCRT(Windows / Linux 客户端都适用)连接 Linux 服务器 为例,说明如何配置 SSH 密钥登录。


一、在 Linux 服务器上生成密钥(服务器端)

登录到你的 Linux 服务器,执行:

ssh-keygen -t rsa -b 4096

一路回车即可(默认生成在 ~/.ssh/):

  • 私钥:~/.ssh/id_rsa
  • 公钥:~/.ssh/id_rsa.pub

将公钥写入授权文件:

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh

二、把私钥下载到本地(Linux SecureCRT 客户端)

如果你在 Linux 上使用 SecureCRT,需要把私钥拷到本地:

scp user@server:~/.ssh/id_rsa ~/.ssh/
chmod 600 ~/.ssh/id_rsa

Windows 用户可用 SecureCRT 的 SFTP / SCP 或 pscp 下载


三、SecureCRT 配置密钥登录

1. 新建或编辑 Session

  • 打开 SecureCRT
  • File → Connect → New Session

2. 设置 SSH 协议

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

3. 配置密钥认证

进入:

Session Options
 → Connection
   → SSH2
     → Authentication

勾选:

  • ✅ PublicKey

点击 Properties:

  • 选择 Use identity file
  • 浏览并选择你本地的私钥文件
    • Linux:~/.ssh/id_rsa
    • Windows:id_rsa

如果私钥有密码(passphrase),连接时会提示输入


四、禁用密码登录(可选,更安全)

在服务器上编辑:

sudo vim /etc/ssh/sshd_config

修改:

PasswordAuthentication no
PubkeyAuthentication yes

重启 SSH:

sudo systemctl restart sshd

五、常见问题

1. 登录仍提示密码?

  • 检查 authorized_keys 权限
  • 检查 SELinux(CentOS):
restorecon -Rv ~/.ssh

2. SecureCRT 不支持 OpenSSH 私钥?

  • 用 SecureCRT 转换:
Tools → Convert Private Key

如果你说的是 “Linux 服务器上的 SecureCRT” 或 “SecureCRT 在 Linux 发行版下的路径/配置目录”,可以告诉我你的系统版本,我可以给更具体的步骤。

0 踩