温馨提示×

linux securecrt如何免密登录

小樊
53
2026-09-12 13:56:42
栏目: 智能运维

在 Linux 下使用 SecureCRT 实现免密登录,本质是使用 SSH 公钥认证。下面给你一套通用、可操作的步骤。


一、在 Linux 本地生成密钥(如果已有可跳过)

在你要登录的客户端机器(运行 SecureCRT 的 Linux 机器)上执行:

ssh-keygen -t rsa -b 4096

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

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

(如用 ed25519 更推荐:ssh-keygen -t ed25519)


二、把公钥放到远程服务器

方法 1:自动方式(推荐)

ssh-copy-id user@remote_host

输入一次密码后,后续即可免密。


方法 2:手动方式

在本地查看公钥:

cat ~/.ssh/id_rsa.pub

登录远程服务器,写入:

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

三、SecureCRT 中配置使用私钥

1. 创建或编辑 Session

  • File → Connect → New Session
  • Protocol 选择 SSH2

2. Authentication 设置

路径(不同版本略有差异):

Connection → SSH2 → Authentication
  • ✅ 勾选 PublicKey
  • 取消或下移 Password
  • 选择私钥文件:
    • 点击 Properties
    • 选择 ~/.ssh/id_rsa

SecureCRT 支持 OpenSSH 格式私钥(新版),老版本如需转换:

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

四、登录测试

直接双击 Session:

Connecting to ...
Authenticated.

✅ 无需输入密码即成功


五、常见问题排查

1. 仍提示输入密码

检查服务器:

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

权限应为:

  • ~:755 或更严格
  • ~/.ssh:700
  • authorized_keys:600

2. SELinux 问题(CentOS/RHEL)

restorecon -Rv ~/.ssh

3. 服务器未开启公钥登录

grep PubkeyAuthentication /etc/ssh/sshd_config

应为:

PubkeyAuthentication yes

修改后重启:

systemctl restart sshd

六、进阶(可选)

  • 私钥加 passphrase(更安全)
  • 使用 ssh-agent 管理密钥
  • 禁止密码登录(更安全):
    PasswordAuthentication no
    

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

  • 你的 SecureCRT 版本
  • 是 本地 Linux 跑 SecureCRT 还是 Windows SecureCRT 连 Linux

我可以给你更精确的截图级配置说明。

0 踩