温馨提示×

linux securecrt如何配密钥

小樊
40
2026-09-03 14:26:07
栏目: 智能运维

下面以 SecureCRT 在 Linux 下配置 SSH 密钥登录 为例,分步骤说明(假设你要登录远程 Linux 服务器)。


一、在本地 Linux 上生成密钥(如果还没有)

打开终端,执行:

ssh-keygen -t rsa -b 4096

一路回车即可,默认会生成:

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

(如需设置密码保护私钥,可在提示时输入 passphrase)


二、把公钥上传到远程服务器

方法 1:使用 ssh-copy-id(推荐)

ssh-copy-id user@remote_host

输入一次密码后,公钥会自动写入服务器的:

~/.ssh/authorized_keys

方法 2:手动复制

在本地查看公钥:

cat ~/.ssh/id_rsa.pub

登录服务器后执行:

mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "粘贴的公钥内容" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

三、SecureCRT 中配置密钥登录

1. 创建或编辑 Session

打开 SecureCRT → Quick ConnectSession Manager

  • Protocol:SSH2
  • Hostname:远程 IP
  • Username:你的用户名

2. 配置 Authentication

进入:

Session Options
  → Connection
    → SSH2
      → Authentication

勾选:

  • ✅ PublicKey
  • ❌ Password(可取消,或放后面)

3. 指定私钥文件

PublicKey 属性中:

  • Properties → Use session public key
  • Use identity file

选择:

~/.ssh/id_rsa

(SecureCRT 支持 OpenSSH 格式私钥)


四、测试连接

点击 Connect

  • 如果设置了 passphrase,会提示输入
  • 成功后即可免密码(或仅私钥密码)登录

五、常见问题

1. SecureCRT 不识别 id_rsa?

  • 确保是 OpenSSH 格式
  • 旧版 SecureCRT 可用:
    ssh-keygen -p -m PEM -f ~/.ssh/id_rsa
    

2. 服务器拒绝密钥?

检查服务器配置:

sudo vi /etc/ssh/sshd_config

确保:

PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

重启:

sudo systemctl restart sshd

3. 权限错误

服务器上:

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

如果你用的是 SecureCRT for Linux 具体版本Windows 连 Linux,可以告诉我,我可以给你更精确的截图级步骤。

0