首先,我想说的是,我已经尝试了这个问题中的所有方法,但都没有帮助:如何在没有密码的情况下通过 SSH 连接到本地主机?
我最近遇到了一个文件权限问题,因为我不知道如何在 Linux 中输入chmod 700 -R /home
,因为我是个笨蛋。这可能与我今天的问题有关。有人帮我解决了这个问题,但我想我会提出来,因为 SSH 对文件权限非常固执。
以下是 SSH 的详细输出日志:
[user@centos ~]$ ssh -v localhost
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/identity type -1
debug1: identity file /home/user/.ssh/identity-cert type -1
debug1: identity file /home/user/.ssh/id_rsa type 1
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: identity file /home/user/.ssh/id_dsa type 2
debug1: identity file /home/user/.ssh/id_dsa-cert type -1
debug1: identity file /home/user/.ssh/id_ecdsa type -1
debug1: identity file /home/user/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
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: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'localhost' is known and matches the RSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:7
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
Credentials cache file '/tmp/krb5cc_500' not found
debug1: Unspecified GSS failure. Minor code may provide more information
Credentials cache file '/tmp/krb5cc_500' not found
debug1: Unspecified GSS failure. Minor code may provide more information
debug1: Unspecified GSS failure. Minor code may provide more information
Credentials cache file '/tmp/krb5cc_500' not found
debug1: Next authentication method: publickey
debug1: Trying private key: /home/user/.ssh/identity
debug1: Offering public key: /home/user/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Offering public key: /home/user/.ssh/id_dsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /home/user/.ssh/id_ecdsa
debug1: Next authentication method: password
user@localhost's password:
以下是 .ssh 目录及其内容的文件权限:
drwx------. 2 user user 4096 Jul 7 08:52 .ssh
drwx------. 2 user user 4096 Jul 7 08:52 .
drwxrwxr-x. 44 user user 4096 Jul 7 08:43 ..
-rw------- 1 user user 2183 Jul 7 08:52 authorized_keys
-rw------- 1 user user 672 Jul 7 08:52 id_dsa
-rw-r--r-- 1 user user 603 Jul 7 08:52 id_dsa.pub
-rw-------. 1 user user 1675 Jul 2 10:55 id_rsa
-rw-r--r--. 1 user user 395 Jul 2 10:55 id_rsa.pub
-rw-r--r-- 1 user user 2733 Jul 2 10:45 known_hosts
编辑:有人要求提供 /var/log/secure 的内容,因此这里提供了。我删除了我的用户名,因为这是我的真名。
Jul 7 08:53:21 centos sshd[2611]: pam_unix(sshd:session): session opened for user *USERNAME REMOVED* by (uid=0)
Jul 7 08:55:25 centos sshd[2648]: Authentication refused: bad ownership or modes for directory /home/*USERNAME REMOVED*
Jul 7 08:55:25 centos sshd[2648]: Authentication refused: bad ownership or modes for directory /home/*USERNAME REMOVED*
Jul 7 08:56:59 centos sshd[2649]: Connection closed by ::1
有人能帮我吗?
答案1
您收到以下错误:
身份验证被拒绝:目录 /home/ 的所有权或模式错误用户名已删除
这似乎意味着(如果你忽略了仅有的您的用户名)对 $HOME 目录具有错误的权限。在我的系统上,我有:
$ ls -lhd .
drwxr-xr-x 104 myname myname 4.0K Jul 7 5:14 .
你有什么不同吗?
顺便说一下, 客户日志几乎没用,你应该使用服务器log,因为这是你自己的电脑。最简单的方法是停止正在运行的 ssh 服务器,然后以 sudo 身份发出
# /usr/sbin/sshd -dD
这会阻止 ssh 守护进程,并且还会增加输出到调试级别。现在,从另一个终端尝试通过 ssh 进入 localhost,
$ ssh myname@localhost
并查看终端中出现的错误消息sshd
。这应该会对您有所帮助,甚至可能更多。