【问题标题】:setting SSH access to localhost设置对 localhost 的 SSH 访问
【发布时间】:2015-04-27 23:24:10
【问题描述】:

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

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

RSA认证是

PubkeyAuthentication 是

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).

【问题讨论】:

    标签: ssh key localhost


    【解决方案1】:

    您是否看过 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
    

    现在我们将生成我们的私钥/公钥:

    (rahul)$ ssh-keygen
    

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

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

    现在尝试连接:

    (rahul)$ ssh rahul@localhost
    

    现在它可以工作了。

    【讨论】:

    • 我尝试了您的建议,但没有运气。 auth.log 有以下错误。 ` PWD=/home/rahul ;用户=根; COMMAND=/bin/bash 2 月 25 日 13:26:07 rahul-ThinkPad-X240 sudo: pam_unix(sudo:session): rahul(uid=0) 为 root 用户打开的会话 2 月 25 日 13:26:37 rahul-ThinkPad- X240 sudo: pam_unix(sudo:session): session closed for user root Feb 25 13:26:42 rahul-ThinkPad-X240 sshd[11371]: Connection closed by 127.0.0.1 [preauth]`
    • 您是否正在尝试连接到用户“root”?在这种情况下,您需要在 /root/.ssh/authorized_keys 中添加您的公钥,而不是 /home/rahul/.ssh/authorized_keys
    • 我实际上不是......我正在做'ssh rahul@localhost'..我不知道为什么它在日志文件中显示root用户。
    • 您使用的是什么 Linux 发行版?我将通过使用默认设置重新安装 openssh-server 并生成新的私钥/公钥并使用 debian/ubuntu 中的 apropiate 命令复制它的步骤来更新我的答案。
    • 我使用的是 ubuntu 14.04,我按照你提到的链接中的所有步骤写信,但仍然无法正常工作......
    猜你喜欢
    • 2013-05-28
    • 2023-03-07
    • 2020-03-31
    • 1970-01-01
    • 2015-11-22
    • 2018-03-23
    • 2011-08-29
    • 2021-01-25
    • 2011-09-17
    相关资源
    最近更新 更多