温馨提示×

ubuntu securecrt怎么设密钥

小樊
43
2026-10-12 19:37:37
栏目: 智能运维

在 Ubuntu 上使用 SecureCRT 通过**密钥(SSH Key)**登录远程服务器,一般分为 生成密钥 和 在 SecureCRT 中配置 两部分。下面按常见做法说明。


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

1️⃣ 生成密钥(如果还没有)

ssh-keygen -t rsa -b 4096

或(更推荐)

ssh-keygen -t ed25519

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

~/.ssh/id_rsa      (私钥)
~/.ssh/id_rsa.pub  (公钥)

如设置密码(passphrase),登录时需输入。


2️⃣ 将公钥上传到服务器

ssh-copy-id user@server_ip

或手动追加:

cat ~/.ssh/id_rsa.pub | ssh user@server_ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

二、在 SecureCRT 中使用密钥登录

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

  1. 打开 SecureCRT
  2. 新建或编辑 Session
  3. 进入:
    Connection → SSH2
    
  4. Authentication 中:
    • 勾选 PublicKey
    • 取消 Password(可选)
  5. 点击 Properties
  6. 选择:
    Use identity file
    
  7. 浏览选择:
    /home/你的用户名/.ssh/id_rsa
    
  8. 保存并连接

✅ 如果生成时设了 passphrase,会提示输入。


方法二:用 SecureCRT 自带工具生成密钥

  1. SecureCRT 菜单:

    Tools → Create Public Key...
    
  2. 选择:

    • Key type: RSA 或 ED25519
    • Key length: 2048 / 4096
  3. 设置 passphrase(可选)

  4. 生成后保存:

    • 私钥(本地)
    • 公钥(上传服务器)
  5. 将公钥内容写入服务器:

    ~/.ssh/authorized_keys
    
  6. Session 中配置方式同上(Use identity file)


三、常见问题排查

❌ 权限问题(非常重要)

服务器上必须设置:

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

❌ SecureCRT 找不到密钥

  • 确认路径是 绝对路径
  • 私钥权限不要过宽(Ubuntu 下 600 最佳)

❌ 仍然提示密码

  • 检查服务器 /etc/ssh/sshd_config
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

改后重启:

sudo systemctl restart ssh

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

  • SecureCRT 版本
  • Ubuntu 版本
  • 是 本地 Ubuntu 用 SecureCRT,还是 连接到 Ubuntu 服务器

我可以给你更精确的步骤。

0 踩