温馨提示×

ubuntu securecrt密钥认证配置

小樊
123
2025-03-22 09:23:03
栏目: 智能运维

在Ubuntu系统中使用SecureCRT进行密钥认证的步骤如下:

生成密钥对

  • 打开SecureCRT,点击左上角的“File”菜单,然后选择“New Session”以创建一个新的会话。
  • 在“Session Options”对话框中,点击左侧的“Terminal”,然后选择“Appearance”子选项卡。
  • 在右侧的“Character encoding”下拉列表中,选择“UTF-8”。
  • 转到“Security”子选项卡,点击“SSH”子选项卡。
  • 在“Key exchange algorithms”列表中,确保已启用“Diffie-Hellman”和“ECDH”。
  • 在“Authentication methods”列表中,勾选“Public key authentication”。
  • 点击“Browse”按钮,然后选择本地计算机上的公钥文件(默认为~/.ssh/id_rsa.pub)。
  • 点击“OK”以保存会话属性并关闭对话框。

上传公钥到Ubuntu服务器

  1. 使用SecureCRT的“工具-创建公钥”功能生成密钥对,选择RSA加密算法,并保存为OpenSSH格式。
  2. 将生成的公钥文件(通常是Identity.pub)上传到Ubuntu服务器的~/.ssh/目录下。如果没有该目录,请手动创建它。
  3. 确保公钥文件的权限设置正确,通常使用命令chmod 600 ~/.ssh/Identity.pub

配置sshd_config文件

  1. 在Ubuntu服务器上,打开/etc/ssh/sshd_config文件进行编辑。
  2. 确保以下配置项已设置为:
    • PubkeyAuthentication yes:启用公钥认证。
    • RSAAuthentication yes:如果使用RSA密钥对进行认证,也需要启用此选项。
    • AuthorizedKeysFile .ssh/Identity.pub:指定公钥文件的位置。
  3. 如果需要禁止密码认证,可以添加或确认以下配置项:
    • PasswordAuthentication no
  4. 保存并关闭sshd_config文件。
  5. 重启SSH服务以应用更改,使用命令sudo systemctl restart sshd

连接到Ubuntu服务器

  1. 使用配置好的SecureCRT会话连接到Ubuntu服务器。
  2. 在连接过程中,系统可能会提示输入用户名,输入相应的用户名后按回车键。
  3. 由于已经启用了公钥认证,因此不需要输入密码即可登录。

如果在连接过程中遇到“No compatible hostkey/key exchange method”错误,可以尝试以下解决方法:

  • 修改/etc/ssh/sshd_config文件,添加或修改以下配置项:
    HostKeyAlgorithms=+ssh-rsa,ssh-dss
    KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
    
  • 重启SSH服务:sudo systemctl restart sshd.service

通过以上步骤,您应该能够在Ubuntu系统中成功配置SecureCRT进行密钥认证。如果在配置过程中遇到任何问题,请检查每一步的配置是否正确,并确保密钥文件的权限设置正确。

0