温馨提示×

Linux SecureCRT怎样设置密钥

小樊
49
2026-07-10 21:59:17
栏目: 智能运维

Linux 下使用 SecureCRT 通过密钥(SSH Key)登录服务器,一般分为 生成密钥 → 上传公钥 → 配置 SecureCRT → 服务器端设置 这几个步骤。下面按常见场景详细说明。


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

1️⃣ 生成密钥对

在本地 Linux 终端执行:

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(最简单)

ssh-copy-id user@server_ip

自动将公钥写入服务器:

~/.ssh/authorized_keys

方法 2:手动上传(无 ssh-copy-id)

scp ~/.ssh/id_rsa.pub user@server_ip:/tmp/

登录服务器后:

mkdir -p ~/.ssh
cat /tmp/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

三、服务器端 SSH 配置确认

编辑服务器 SSH 配置:

sudo vi /etc/ssh/sshd_config

确保以下配置存在且未被注释:

PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

重启 SSH 服务:

sudo systemctl restart sshd

四、SecureCRT 使用密钥登录(重点)

方式一:直接使用 Linux 生成的密钥(推荐)

  1. 打开 SecureCRT
  2. File → Connect → New Session
  3. Protocol 选择 SSH2
  4. Hostname 填写服务器 IP
  5. Username 填写服务器用户名
  6. 点击 Authentication → PublicKey
  7. 勾选 Use identity file
  8. 选择私钥文件:
    ~/.ssh/id_rsa
    
    (SecureCRT 支持 OpenSSH 格式)

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


方式二:使用 SecureCRT 自带密钥生成器

  1. Tools → Create Public Key
  2. 选择密钥类型:
    • RSA(兼容性好)
  3. Passphrase:建议设置
  4. 保存为:
    • Private Key:id_secrt
    • Public Key:id_secrt.pub
  5. 公钥内容 追加到服务器:
    cat id_secrt.pub >> ~/.ssh/authorized_keys
    

⚠️ 注意:SecureCRT 生成的公钥格式与 OpenSSH 略有不同,需确认服务器支持。


五、常见问题排查

❌ SecureCRT 提示 “No supported authentication methods available”

✅ 检查:

  • 服务器是否开启 PubkeyAuthentication
  • 私钥路径是否正确
  • 私钥权限:
    chmod 600 ~/.ssh/id_rsa
    

❌ 服务器拒绝密钥

ssh -vvv user@server_ip

✅ 检查:

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

六、推荐安全配置(可选)

  • 禁用密码登录(确认密钥可用后):
    PasswordAuthentication no
    
  • 使用非 root 用户
  • 私钥设置 passphrase

七、总结流程

Linux 生成密钥
   ↓
上传公钥到服务器
   ↓
服务器开启公钥认证
   ↓
SecureCRT 指定私钥登录

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

  • ✅ SecureCRT 版本
  • ✅ Linux 发行版
  • ✅ 是否是 跳板机 / 多服务器

我可以给你 更精确的配置示例

0