在远程服务器上设置无密码登录

在远程服务器上设置无密码登录

我正在尝试设置无密码登录我用于工作的远程服务器。目前我每次登录时都必须输入密码,然后再次切换到使用appusersudo su - appuser我首先尝试将我的本地公钥添加到服务器。我在本地机器上生成了一个密钥对,并使用 ssh-copy-id 将我的公钥复制到文件中/export/home/myusername/.ssh/authorized_keys。我还仔细检查了权限:chmod 700 .ssh; chmod 640 .ssh/authorized_keys。为什么一切完成后仍提示我输入密码?

这是使用-vv

OpenSSH_8.1p1, LibreSSL 2.7.3
    debug1: Reading configuration data /Users/user/.ssh/config
    debug1: /Users/user/.ssh/config line 1: Applying options for server1
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: /etc/ssh/ssh_config line 47: Applying options for *
    debug1: Connecting to server1 port 22.
    debug1: Connection established.
    .....
    debug1: Host 'server1' is known and matches the ECDSA host key.
    debug1: Found key in /Users/users/.ssh/known_hosts:7
    debug2: set_newkeys: mode 1
    debug1: rekey out after 134217728 blocks
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug1: SSH2_MSG_NEWKEYS received
    debug2: set_newkeys: mode 0
    debug1: rekey in after 134217728 blocks
    debug1: Will attempt key: /Users/user/.ssh/id_rsa RSA SHA256:...
    debug1: Will attempt key: /Users/user/.ssh/id_dsa 
    debug1: Will attempt key: /Users/user/.ssh/id_ecdsa 
    debug1: Will attempt key: /Users/user/.ssh/id_ed25519 
    debug1: Will attempt key: /Users/user/.ssh/id_xmss 
    debug2: pubkey_prepare: done
    debug1: SSH2_MSG_EXT_INFO received
    debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
    debug2: service_accept: ssh-userauth
    debug1: SSH2_MSG_SERVICE_ACCEPT received

 Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/user/.ssh/id_rsa RSA SHA256:...
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /Users/user/.ssh/id_dsa
debug1: Trying private key: /Users/user/.ssh/id_ecdsa
debug1: Trying private key: /Users/user/.ssh/id_ed25519
debug1: Trying private key: /Users/user/.ssh/id_xmss
debug2: we did not send a packet, disable method
debug1: Next authentication method: password

答案1

尝试手动将 /home/user/.ssh/id_rsa.pub 密钥复制到远程服务器 -> /home/user/.ssh/authorized_keys 。

您还可以尝试:

ssh user@remoteserver -i /home/user/.ssh/id_rsa(不带.pub)。

相关内容