温馨提示×

SecureCRT Debian密钥如何用

小樊
40
2026-07-15 16:59:49
栏目: 智能运维

Debian 上使用 SecureCRT 进行密钥(SSH Key)认证,一般分为 生成密钥配置 SecureCRT 连接 两部分。下面按最常见、最安全的方式一步一步说明(适用于 SecureCRT 9.x / 8.x)。


一、准备工作

  • 系统:Debian / Ubuntu
  • 已安装并运行 SSH Server
  • 客户端使用的是 SecureCRT

先确认 SSH 服务已启用:

sudo systemctl status ssh

如果未启动:

sudo apt install openssh-server
sudo systemctl enable ssh
sudo systemctl start ssh

二、使用 SecureCRT 生成密钥(推荐)

1️⃣ 打开 SecureCRT → 生成密钥

Tools(工具) → Create Public Key...

按向导操作:

  • Key Type(密钥类型)
    ✅ 推荐:RSAED25519

    • RSA:2048 / 4096 位
    • ED25519:更现代、更安全
  • Passphrase(私钥密码)
    建议设置(防止私钥被拷走滥用)

  • Key Format(密钥格式) ✅ 选择 OpenSSH
    ❌ 不要用 SecureCRT 专有格式(不方便服务器使用)

  • 保存路径

    • 私钥:id_rsa / id_ed25519
    • 公钥:id_rsa.pub

三、将公钥上传到 Debian 服务器

方法 1:手动上传(最常用)

1️⃣ 登录服务器

ssh user@debian_ip

2️⃣ 创建 .ssh 目录(如果不存在)

mkdir -p ~/.ssh
chmod 700 ~/.ssh

3️⃣ 将 SecureCRT 生成的 .pub 内容写入 authorized_keys

nano ~/.ssh/authorized_keys

粘贴公钥内容(一行)

4️⃣ 设置权限(非常重要)

chmod 600 ~/.ssh/authorized_keys

四、配置 SecureCRT 使用密钥登录

1️⃣ 新建或编辑 Session

Session Options → SSH2

2️⃣ 设置认证方式

  • Authentication ✅ PublicKey ❌ Password(可选关闭)

3️⃣ 指定私钥

PublicKey → Properties → Use session public key

选择刚才生成的 私钥文件


五、服务器端 SSH 配置检查(重要)

编辑 SSH 配置:

sudo nano /etc/ssh/sshd_config

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

PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

(可选)禁用密码登录:

PasswordAuthentication no

重启 SSH:

sudo systemctl restart ssh

六、常见问题排查

❌ 仍然提示输入密码

检查:

ls -ld ~/.ssh
ls -l ~/.ssh/authorized_keys

权限必须是:

.ssh → 700
authorized_keys → 600

❌ SecureCRT 提示“Key exchange failed”

  • 确认服务器支持对应算法
  • 可尝试 RSA 4096

❌ 服务器是 root 用户

Debian 默认可能禁止 root 登录:

PermitRootLogin prohibit-password

七、推荐安全组合 ✅

项目 推荐
密钥类型 ED25519
私钥密码 设置
SSH 端口 非 22
登录方式 仅密钥
防火墙 ufw / iptables

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

  • ✅ SecureCRT 版本
  • ✅ Debian 版本
  • ✅ 是否用 root / 普通用户

我可以直接给你 针对你环境的精确配置命令

0