LINUX.ORG.RU

Не удается подключиться с использованием SSH-ключа

 , ,


0

1

Доброго времени суток!

Не удаётся подключиться к серверу на Ubuntu 19.10, используя SSH-ключ, лог подключения:

ssh 'user2@192.168.2.4' -vvv
...
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 public key: user1@host RSA SHA256:j93L8tDfD46Sjl4b9KKcH6pMbdPEpSGVwI55/jToTW0 agent
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
debug1: Offering public key: user1@host ED25519 SHA256:z0y9igtjXtHDH9xTWlCHPnP8mWAA2HgMC8hDVxM/5Jg agent
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/user1/.ssh/id_dsa
debug3: no such identity: /home/user1/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/user1/.ssh/id_ecdsa
debug3: no such identity: /home/user1/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/user1/.ssh/id_ecdsa_sk
debug3: no such identity: /home/user1/.ssh/id_ecdsa_sk: No such file or directory
debug1: Trying private key: /home/user1/.ssh/id_ed25519_sk
debug3: no such identity: /home/user1/.ssh/id_ed25519_sk: No such file or directory
debug1: Trying private key: /home/user1/.ssh/id_xmss
debug3: no such identity: /home/user1/.ssh/id_xmss: 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
user2@192.168.2.4's password:

Что сделано на клиенте:

$ ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa
$ ssh-copy-id -i ~/.ssh/id_rsa.pub user2@192.168.2.4
$ ssh-add ~/.ssh/id_rsa
$ ssh-keygen -t ssh-ed25519 -b 2048 -f ~/.ssh/id_ed25519
$ ssh-copy-id -i ~/.ssh/id_ed25519.pub user2@192.168.2.4
$ ssh-add ~/.ssh/id_ed25519

Что отображается в логах на сервере в /var/log/auth.log:

Jan 18 15:34:18 server kernel: [   10.189545] systemd-logind[321]: Configuration file /etc/systemd/logind.conf is muser2ed executable. Please remove executable permission bits. Proceeding anyway.
Jan 18 15:34:18 server kernel: [   10.189719] systemd-logind[321]: Configuration file /etc/systemd/logind.conf is muser2ed world-writable. Please remove world writability permission bits. Proceeding anyway.
Jan 18 15:34:18 server kernel: [   10.198550] systemd-logind[321]: New seat seat0.
Jan 18 15:34:18 server kernel: [  227.215758] systemd-logind[321]: New session c1 of user user2.
Jan 18 15:34:18 server kernel: [  355.438257] systemd-logind[321]: Session c1 logged out. Waiting for processes to exit.
Jan 18 15:34:18 server kernel: [  355.445270] systemd-logind[321]: Removed session c1.
Jan 18 15:34:18 server kernel: [  372.078823] systemd-logind[321]: New session c2 of user user2.
Jan 18 15:34:18 server kernel: [  622.830058] systemd-logind[321]: Session c2 logged out. Waiting for processes to exit.
Jan 18 15:34:18 server kernel: [  622.836920] systemd-logind[321]: Removed session c2.
Jan 18 15:34:18 server kernel: [  937.360051] systemd-logind[321]: New session c3 of user user2.
Jan 18 15:34:18 server kernel: [ 1015.144938] systemd-logind[321]: Session c3 logged out. Waiting for processes to exit.
Jan 18 15:34:18 server kernel: [ 1015.155507] systemd-logind[321]: Removed session c3.
Jan 18 15:34:18 server kernel: [ 1023.231066] systemd-logind[321]: New session c4 of user user2.
Jan 18 15:34:44 server kernel: [ 1517.236174] systemd-logind[321]: Session c4 logged out. Waiting for processes to exit.
Jan 18 15:34:44 server kernel: [ 1517.242989] systemd-logind[321]: Removed session c4.
Jan 18 15:34:54 server kernel: [ 1527.564143] systemd-logind[321]: New session c5 of user user2.
Jan 18 15:50:28 server kernel: [ 2461.936174] systemd-logind[321]: New session c6 of user user2.
Jan 18 15:50:29 server kernel: [ 2462.100875] systemd-logind[321]: Session c6 logged out. Waiting for processes to exit.
Jan 18 15:50:29 server kernel: [ 2462.106304] systemd-logind[321]: Removed session c6.
Jan 18 16:01:23 server kernel: [ 3116.928845] systemd-logind[321]: New session c7 of user user2.

Вывод /etc/ssh/sshd_config на сервере:

#	$OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
AuthorizedKeysFile	/home/user2/.ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no


Последнее исправление: ameame2021 (всего исправлений: 1)
AuthorizedKeysFile	/home/user2/.ssh/authorized_keys

этошедевр!

vel ★★★★★
()
Ответ на: комментарий от detes42325
$ ssh -i ~/.ssh/id_rsa user2@192.168.2.4 -vvv
...
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,ext-info-c
debug2: host key algorithms: ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,rsa-sha2-512,rsa-sha2-256
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MACs ctos: 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
debug2: MACs stoc: 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
debug2: compression ctos: none,zlib@openssh.com,zlib
debug2: compression stoc: none,zlib@openssh.com,zlib
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1
debug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MACs ctos: 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
debug2: MACs stoc: 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
debug2: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:lVizlC0DLx4YMwtGyU+/xBviuyMoKCSg+roUUZJTTdA
debug3: record_hostkey: found key type ED25519 in file /home/user1/.ssh/known_hosts:19
debug3: record_hostkey: found key type RSA in file /home/user1/.ssh/known_hosts:20
debug3: record_hostkey: found key type ECDSA in file /home/user1/.ssh/known_hosts:21
debug3: load_hostkeys_file: loaded 3 keys from 192.168.2.4
debug1: load_hostkeys: fopen /home/user1/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host '192.168.2.4' is known and matches the ED25519 host key.
debug1: Found key in /home/user1/.ssh/known_hosts:19
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /home/user1/.ssh/id_rsa RSA SHA256:j93L8tDfD46Sjl4b9KKcH6pMbdPEpSGVwI55/jToTW0 explicit agent
debug1: Will attempt key: user1@host ED25519 SHA256:z0y9igtjXtHDH9xTWlCHPnP8mWAA2HgMC8hDVxM/5Jg agent
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 7
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
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 public key: /home/user1/.ssh/id_rsa RSA SHA256:j93L8tDfD46Sjl4b9KKcH6pMbdPEpSGVwI55/jToTW0 explicit agent
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
debug1: Offering public key: user1@host ED25519 SHA256:z0y9igtjXtHDH9xTWlCHPnP8mWAA2HgMC8hDVxM/5Jg agent
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
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
user2@192.168.2.4's password:
ameame2021
() автор топика
Ответ на: комментарий от ameame2021

Сервер игнорирует:

debug1: Next authentication method: publickey
debug1: Offering public key: /home/user1/.ssh/id_rsa RSA SHA256:j93L8tDfD46Sjl4b9KKcH6pMbdPEpSGVwI55/jToTW0 explicit agent
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
debug1: Offering public key: user1@host ED25519 SHA256:z0y9igtjXtHDH9xTWlCHPnP8mWAA2HgMC8hDVxM/5Jg agent
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
debug2: we did not send a packet, disable method
ameame2021
() автор топика

Проблема решена. Судя по всему были некорректные права на ~/.ssh, authorized_keys.

ameame2021
() автор топика

Конечно извините, но… debug1: Trying private key: /home/user1/.ssh/id_dsa и тут же ssh -i ~/.ssh/id_rsa user2@192.168.2.4 это просто гигастрайк. А уже вижу ещё один комментарий, по поводу шедевральности.

grishowwise
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.