首页 文章

设置对localhost的SSH访问

提问于
浏览
0

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

我使用ssh-keygen创建了id_rsa密钥 . 我在.ssh中添加了id_rsa.pub到authroized_keys /我确保了authorized_keys的权限是640我在sshd_config中启用了公钥验证并重新启动了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).

1 回答

  • 2

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

    现在它可能会奏效 .

相关问题