Rhy*_*yuk 7 linux solaris ssh ssh-keys
我正在尝试使用 SSH 密钥设置从 ServerA(SunOS)到 ServerB(一些带有键盘交互登录的自定义 Linux)的访问权限。作为概念证明,我能够在 2 个虚拟机之间进行。现在在我的现实生活场景中它不起作用。
我在 ServerA 中创建了密钥,将它们复制到 ServerB,在 ServerA、B 上将 .ssh 文件夹修改为 700。
这是我得到的日志。
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: Peer sent proposed langtags, ctos:
debug1: Peer sent proposed langtags, stoc:
debug1: We proposed langtags, ctos: en-US
debug1: We proposed langtags, stoc: en-US
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: dh_gen_key: priv key bits set: 125/256
debug1: bits set: 1039/2048
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'XXX.XXX.XXX.XXX' is known and matches the RSA host key.
debug1: Found key in /XXX/.ssh/known_hosts:1
debug1: bits set: 1061/2048
debug1: ssh_rsa_verify: signature correct
debug1: newkeys: mode 1
debug1: set_newkeys: setting new keys for 'out' mode
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: newkeys: mode 0
debug1: set_newkeys: setting new keys for 'in' mode
debug1: SSH2_MSG_NEWKEYS received
debug1: done: ssh_kex2.
debug1: send SSH2_MSG_SERVICE_REQUEST
debug1: got SSH2_MSG_SERVICE_ACCEPT
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: /XXXX/.ssh/identity
debug1: Trying public key: /xxx/.ssh/id_rsa
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Trying private key: /xxx/.ssh/id_dsa
debug1: Next authentication method: keyboard-interactive
Password:
Password:
Run Code Online (Sandbox Code Playgroud)
ServerB 的操作非常有限,因为它是一个自定义的专有 linux。
会发生什么?
编辑答案:
问题是我没有在 sshd_config 中启用这些设置(请参阅接受的答案)并且在将密钥从 ServerA 粘贴到 ServerB 时,它会将密钥解释为 3 个单独的行。
我所做的是,以防万一你不能像我一样使用 ssh-copy-id。将密钥的第一行粘贴到“ServerB”authorized_keys 文件中,不包含最后 2 个字符,然后自己键入第 1 行中缺少的字符和第 2 行中的第一个字符,这将防止在第一个和第一个之间添加“新行”键的第二行。用 3d 线重复。
ash*_*ash 12
我认为您的密钥没有被正确复制,如果您有ssh-copy-id可用的,我会建议您使用它。
$ ssh-copy-id user@remote_server
Password:
Run Code Online (Sandbox Code Playgroud)
输入密码后,您的 SSH 密钥将被复制,您应该可以在不再次提供密码的情况下进行 ssh。
还要检查ServerB上的 SSH 配置并检查几件事。
$ vi /etc/ssh/sshd_config
Run Code Online (Sandbox Code Playgroud)
另一件事是检查这些设置:
RSAAuthentication yes
PubKeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)
AuthorizedKeysFile的值是您需要粘贴公共 ssh 密钥的位置。
您可以使用以下方法收集 SSH 密钥信息: ssh-add -L
更新
当ssh-copy-id不存在时,您可以使用旧方法:
$ cat ~/.ssh/id_rsa.pub | ssh user@remote_host 'cat >> /home/user/.ssh/authorized_keys'
Run Code Online (Sandbox Code Playgroud)
小智 5
您应该使用以下命令检查远程计算机上文件的权限ls -l ~/.ssh并设置权限:
chmod 600 ~/.ssh/authorized_keys
chmod 600 ~/.ssh/<private_key>Ex: chmod 600 ~/.ssh/id_rsa
chmod 700 ~/.ssh/<public_key>Ex:chmod 700 ~/.ssh/id_rsa.pub
chmod 700 /home/vmirea/.ssh