温馨提示×

ubuntu securecrt如何设密钥

小樊
48
2026-10-01 03:20:02
栏目: 智能运维

在 Ubuntu 上使用 SecureCRT 配置 密钥登录(SSH 公钥认证),一般分三步:生成密钥 → 上传公钥到服务器 → SecureCRT 使用私钥连接。下面详细说明。


一、在 Ubuntu 上生成密钥(推荐用 ssh-keygen)

打开终端,执行:

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 user@server_ip

方法 2(手动)

cat ~/.ssh/id_rsa.pub

复制内容,登录服务器后:

mkdir -p ~/.ssh
chmod 700 ~/.ssh
vi ~/.ssh/authorized_keys
# 粘贴公钥
chmod 600 ~/.ssh/authorized_keys

三、在 SecureCRT 中使用私钥

1️⃣ 转换私钥格式(重要)

SecureCRT 不能直接用 OpenSSH 的私钥,需要转换:

ssh-keygen -p -m PEM -f ~/.ssh/id_rsa

然后用 SecureCRT 自带的工具:

  • 打开 SecureCRT
  • Tools → Convert Private Key to SecureCRT Format
  • 选择 ~/.ssh/id_rsa
  • 保存为 .ini 或 .pem

2️⃣ 新建 SSH 会话

  1. File → Connect → New Session
  2. Protocol 选 SSH2
  3. Hostname:服务器 IP
  4. Username:服务器用户名
  5. 点击 Properties → SSH2
  6. Authentication 选择 PublicKey
  7. 点击 Properties
    • 选择转换后的私钥文件
    • 如有 passphrase 填写

四、常见问题

❌ SecureCRT 提示“No supported authentication methods”

  • 公钥未写入 authorized_keys
  • 文件权限错误
  • 用了 OpenSSH 私钥未转换

✅ 正确权限

服务器上:

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

五、可选:禁用密码登录(更安全)

服务器 /etc/ssh/sshd_config:

PasswordAuthentication no

重启:

sudo systemctl restart ssh

如果你是用 SecureCRT for Linux 还是 Windows 连 Ubuntu 服务器,可以告诉我,我可以给你更精确的步骤。

0 踩