哪里是非登录用户的.ssh / authorized_keys文件?

时间:2017-05-14 04:49:05

标签: linux git ssh

在我的git docker容器中,我创建了一个非登录用户git

在/ etc / passwd文件中: git:x:997:996::/tmp/git:/usr/bin/git-shell

我想用RSA而不是密码登录git。

我将.ssh/authorized_keys/tmp/git下的id_rsa.pub密钥附加到/home/git(用户git是非登录用户。所以我创建了这个目录)。

但两者都不起作用!

我尝试与用户root一起使用,我将rsa.pub键附加到〜/ .ssh / authorized_keys。

有效!

那么,非登录git用户的.ssh / authorized_keys文件在哪里?

另一方面,在我的计算机(远程到git服务器),ssh -p 2222 -Tv ssh://git@100.200.100.20

它需要密码。

OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /home/Aario/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to 100.200.100.20 [100.200.100.20] port 2222.
debug1: Connection established.
debug1: identity file /home/Aario/.ssh/id_rsa type 1
debug1: identity file /home/Aario/.ssh/id_rsa-cert type -1
debug1: identity file /home/Aario/.ssh/id_dsa type -1
debug1: identity file /home/Aario/.ssh/id_dsa-cert type -1
debug1: identity file /home/Aario/.ssh/id_ecdsa type -1
debug1: identity file /home/Aario/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/Aario/.ssh/id_ed25519 type -1
debug1: identity file /home/Aario/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: curve25519-sha256@libssh.org need=16 dh_need=16
debug1: kex: curve25519-sha256@libssh.org need=16 dh_need=16
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 1e:f3:f2:6b:45:95:b9:95:f1:ed:da:77:23:cc:d2:11
debug1: Host '[100.200.100.20]:2222' is known and matches the ECDSA host key.
debug1: Found key in /home/AAario/.ssh/known_hosts:1
debug1: ssh_ecdsa_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
No Kerberos credentials available (default cache: KEYRING:persistent:1000)

debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:1000)

debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/Aario/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /home/Aario/.ssh/id_dsa
debug1: Trying private key: /home/Aario/.ssh/id_ecdsa
debug1: Trying private key: /home/Aario/.ssh/id_ed25519
debug1: Next authentication method: password
git@100.200.100.20's password:

在git服务器容器中,我使用用户root登录,我尝试这些: cat ~/.ssh/id_rsa.pub >> /tmp/git/.ssh/authorized_keysssh -Tv git@localhost。它说:

OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: curve25519-sha256@libssh.org need=16 dh_need=16
debug1: kex: curve25519-sha256@libssh.org need=16 dh_need=16
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 1e:f3:f2:6b:45:95:b9:95:f1:ed:da:77:23:cc:d2:11
debug1: Host 'localhost' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: ssh_ecdsa_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
No Kerberos credentials available (default cache: KEYRING:persistent:0)

debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:0)

debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: Next authentication method: password
git@localhost's password:

2 个答案:

答案 0 :(得分:1)

确保.ssh目录和密钥文件的权限正确无误:https://unix.stackexchange.com/questions/37164/ssh-and-home-directory-permissions

答案 1 :(得分:1)

您的/tmp目录可能是世界可写的。

如果你man sshd,你可能会注意到底部的一个部分,其中包括:

  

<强>的〜/ .ssh /

          此目录是所有特定于用户的配置的默认位置           和身份验证信息。没有一般要求保持           这个目录的全部内容是秘密的,但建议的权限           是用户的读/写/执行,其他人无法访问。

您可以从中获取的提示是权限很重要。现在考虑一下这个用户的主目录的位置。谁拥有您的/tmp目录的写权限?

检查ssh服务器的身份验证日志(可能是/ var / log / security或/var/log/auth.log),看看是否有关于权限错误的消息。

如果sshd无法相信用户的配置未被篡改,则会拒绝访问。