设置对本地主机的 SSH 访问

setting SSH access to localhost

我正在尝试设置 ssh 访问我自己的本地计算机。

我使用 ssh-keygen 创建了 id_rsa 密钥。 我在 .ssh/ 中将 id_rsa.pub 添加到 authroized_keys 我确保 authorized_keys 的权限是 640 我在 sshd_config 中启用了 public-key 身份验证并重新启动了 ssh

RSAAuthentication yes

PubkeyAuthentication yes

AuthorizedKeysFile %u/.ssh/authorized_keys

但是我无法登录到 ssh。

我收到的错误如下

debug3: load_hostkeys: loaded 1 keys
debug1: Host 'localhost' is known and matches the ECDSA host key.
debug1: Found key in /home/rahul/.ssh/known_hosts:6
debug1: ssh_ecdsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug2: key: /home/rahul/.ssh/id_rsa (0x7fa12de58e70),
debug2: key: /home/rahul/.ssh/gitHubKey ((nil)), explicit
debug2: key: /home/rahul/.ssh/id_rsa_buhlServer (0x7fa12de59060), explicit
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/rahul/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/rahul/.ssh/gitHubKey
no such identity: /home/rahul/.ssh/gitHubKey: No such file or directory
debug1: Offering RSA public key: /home/rahul/.ssh/id_rsa_buhlServer
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).

你有没有看到 auth.log(或 system.log、secure.log,等等 opensshd 写日志的地方)可能问题是 .ssh/authorized_keys 必须有 600 而不是 640 .

示例:https://help.ubuntu.com/community/SSH/OpenSSH/Keys

chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

希望对您有所帮助。

编辑:

我们将卸载 openssh-server 并清除配置文件:

(root)# apt-get remove --purge openssh-server

现在我们将使用默认设置再次安装:

(root)# apt-get install openssh-server

现在我们将生成 private/public 密钥:

(rahul)$ ssh-keygen

现在我们将密钥复制到本地用户中,您需要输入密码。

(rahul)$ ssh-copy-id rahul@localhost

立即尝试连接:

(rahul)$ ssh rahul@localhost

现在可能有用了。