R
R
romaro2021-03-10 11:47:25
linux
romaro, 2021-03-10 11:47:25

Why doesn't SSH key authorization work?

The problem occurs frequently, but I have not yet found a solution that will help me.

I'm trying to connect from Win10 to Oracle Linux 8.3 raised locally in a VM.

OpenSSH version on the client: OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
On the server: OpenSSH_8.0p1, OpenSSL 1.1.1g FIPS

Algorithm:
1) Using the ssh-keygen utility, I generated a pair of keys, they appeared in my profile folder C:\Users\Roma\ .ssh
2) On the server, I created a directory for the nodejs user /home/nodejs/.ssh/authorized_keys and put is_rsa.pub in it
3) Made the .ssh file and the nodejs:users user file remote and gave permissions 700
4) Checked that in / etc/ssh/sshd_config line "PubkeyAuthentication yes" is not commented out
5) I set up port forwarding of the 22nd port to the virtual machine, I checked that I can log in via WinSCP (using a password).

When I try to connect with the command:
ssh -v localhost

I get the log:

debug1: Reading configuration data C:\\Users\\Roma/.ssh/config
debug1: C:\\Users\\Roma/.ssh/config line 1: Applying options for localhost
debug1: Connecting to localhost [::1] port 22.
debug1: connect to address ::1 port 22: Connection refused
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: identity file C:\\Users\\Roma/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Roma/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Roma/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Roma/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Roma/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Roma/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Roma/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Roma/.ssh/id_ed25519-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Roma/.ssh/id_xmss type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Roma/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.7
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.0
debug1: match: OpenSSH_8.0 pat OpenSSH* compat 0x04000000
debug1: Authenticating to localhost:22 as 'nodejs'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:lIEJUSqFGQ90czXuJzvda7VNciQOxHVm2XL4bEE5Z/I
debug1: Host 'localhost' is known and matches the ECDSA host key.
debug1: Found key in C:\\Users\\Roma/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
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>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:wobbldI9m9m9rs+KGa+7jyVTnYu2nSEkp4qwHIoS3zI C:\\Users\\Roma/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: C:\\Users\\Roma/.ssh/id_dsa
debug1: Trying private key: C:\\Users\\Roma/.ssh/id_ecdsa
debug1: Trying private key: C:\\Users\\Roma/.ssh/id_ed25519
debug1: Trying private key: C:\\Users\\Roma/.ssh/id_xmss
debug1: Next authentication method: password
debug1: read_passphrase: can't open /dev/tty: No such file or directory
[email protected]'s password:

That is, the key, as I understand it, is sent?

I did not find authorization logs on the server:
[[email protected] ~]# find /var -name *auth*
/var/lib/selinux/targeted/active/modules/100/authconfig
/var/lib/selinux/targeted/active/modules/100/authlogin
/var/lib/selinux/targeted/active/modules/100/pwauth
/var/lib/polkit-1/localauthority
/var/lib/authselect
[[email protected] ~]#


What could be the problem?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
V
Vladimir Pilipchuk, 2021-03-10
@romaro

Use ssh-copy-id. Full-fledged Linux is available on modern Windows.
Alternatively, ssh-copy-id for Windows comes with git for Windows.
You can do the same manually

type $env:USERPROFILE\.ssh\id_rsa.pub | ssh {IP-ADDRESS-OR-FQDN} "cat >> .ssh/authorized_keys"

And yes, authorized_keys is a file.

M
Maxim Grishin, 2021-03-10
@vesper-bot

> ) On the server, I created a directory for the nodejs user /home/nodejs/.ssh/authorized_keys and put is_rsa.pub
authorized_keys in it, this is a file, not a directory, and you need to write the contents of id_rsa.pub into it (before/before) write.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question