Доброго времени суток!
Не удаётся подключиться к серверу на 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