Ssh需要用公钥密码吗?

时间:2016-03-01 13:22:33

标签: ssh gitlab

我在服务器上安装gitlab。使用web-browser添加公钥。 在authorized_keys中添加公钥。

当我连接到服务器whithin ssh时,服务器询问密码(为什么?)。当我尝试克隆repo时使用ssh,服务器请求密码,但每次传递失败(root,my_gitlab_login,main_server_user)!跨越http工作!

我想在没有密码的情况下工作,当我连接到服务器whithin ssh时,以及当我尝试克隆git-repo时。

$ ssh nozdrin@192.168.3.23
nozdrin@192.168.3.23's password: 
nozdrin@debian1:~$ ls -al .ssh
total 12
drwx------ 2 nozdrin nozdrin 4096 Feb 17 18:21 .
drwxr-xr-x 4 nozdrin nozdrin 4096 Mar  1 15:29 ..
-rw------- 1 nozdrin nozdrin  798 Mar  1 15:22 authorized_keys

nozdrin@debian1:~$ ls -al
total 52
drwxr-xr-x 4 nozdrin nozdrin  4096 Mar  1 15:29 .
drwxr-xr-x 3 root    root     4096 Feb 17 15:33 ..
...
drwx------ 2 nozdrin nozdrin  4096 Feb 17 18:21 .ssh
...
nozdrin@debian1:~$

我尝试更改权限(700755),但无论如何都需要密码。

档案/etc/ssh/sshd_config

...
# Authentication:
LoginGraceTime 120
PermitRootLogin without-password
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      %h/.ssh/authorized_keys
...

调试:

$ ssh -vvv nozdrin@192.168.3.23
OpenSSH_7.1p2, OpenSSL 1.0.2f  28 Jan 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.3.23 [192.168.3.23] port 22.
debug1: Connection established.
debug1: identity file /home/nozdrin/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/nozdrin/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/nozdrin/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/nozdrin/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/nozdrin/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/nozdrin/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/nozdrin/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/nozdrin/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.1
debug1: Remote protocol version 2.0, remote software version lshd-2.1 lsh - a GNU ssh
debug1: no match: lshd-2.1 lsh - a GNU ssh
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 192.168.3.23:22 as 'nozdrin'
debug3: hostkeys_foreach: reading file "/home/nozdrin/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/nozdrin/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from 192.168.3.23
debug3: order_hostkeyalgs: prefer hostkeyalgs: ssh-rsa-cert-v01@openssh.com,ssh-rsa
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1
debug2: kex_parse_kexinit: ssh-rsa-cert-v01@openssh.com,ssh-rsa,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519
debug2: kex_parse_kexinit: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-md5-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-md5-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: 
debug2: first_kex_follows 0 
debug2: reserved 0 
debug2: kex_parse_kexinit: diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,spki-sign-rsa
debug2: kex_parse_kexinit: aes256-cbc,3des-cbc,blowfish-cbc,arcfour
debug2: kex_parse_kexinit: aes256-cbc,3des-cbc,blowfish-cbc,arcfour
debug2: kex_parse_kexinit: hmac-sha1,hmac-md5
debug2: kex_parse_kexinit: hmac-sha1,hmac-md5
debug2: kex_parse_kexinit: none,zlib
debug2: kex_parse_kexinit: none,zlib
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: 
debug2: first_kex_follows 0 
debug2: reserved 0 
debug1: kex: server->client 3des-cbc hmac-sha1 none
debug1: kex: client->server 3des-cbc hmac-sha1 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug2: bits set: 990/2048
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Server host key: ssh-rsa SHA256:thxsjPNxAZvauMxRpcF/UHXFULlduZmrCR+PoAmeECA
debug3: hostkeys_foreach: reading file "/home/nozdrin/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/nozdrin/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from 192.168.3.23
debug1: Host '192.168.3.23' is known and matches the RSA host key.
debug1: Found key in /home/nozdrin/.ssh/known_hosts:1
debug2: bits set: 996/2048
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: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/nozdrin/.ssh/id_rsa (0x55d1af1acd60),
debug2: key: /home/nozdrin/.ssh/id_dsa ((nil)),
debug2: key: /home/nozdrin/.ssh/id_ecdsa ((nil)),
debug2: key: /home/nozdrin/.ssh/id_ed25519 ((nil)),
debug1: Authentications that can continue: password,publickey
debug3: start over, passed a different list password,publickey
debug3: preferred 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/nozdrin/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: password,publickey
debug1: Trying private key: /home/nozdrin/.ssh/id_dsa
debug3: no such identity: /home/nozdrin/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/nozdrin/.ssh/id_ecdsa
debug3: no such identity: /home/nozdrin/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/nozdrin/.ssh/id_ed25519
debug3: no such identity: /home/nozdrin/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
nozdrin@192.168.3.23's password: 
debug2: we sent a password packet, wait for reply
debug1: Authentication succeeded (password).
Authenticated to 192.168.3.23 ([192.168.3.23]:22).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Entering interactive session.
debug2: callback start
debug2: fd 3 setting TCP_NODELAY
debug3: ssh_packet_set_tos: set IP_TOS 0x10
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug2: channel 0: request shell confirm 1
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32668
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 10000
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0

尝试ssh-agenssh-add并重新生成密钥 - 无法正常工作(

1 个答案:

答案 0 :(得分:0)

您是否尝试通过复制粘贴生成authorized_keys文件?根据我的经验,使用scp将公钥复制到authorized_keys文件中会产生差异:

 scp -P <port number> -i <identity key> <local source file> <vm-user@ip:/destination directory and file>