@romaro

Почему не работает авторизация по ключу SSH?

Проблема встречается часто, но я пока не нашел решения, которое мне поможет.

Я пытаюсь подключиться из Win10 к Oracle Linux 8.3, поднятой локально на виртуальной машине.

Версия OpenSSH на клиенте: OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
На сервере: OpenSSH_8.0p1, OpenSSL 1.1.1g FIPS

Алгоритм:
1) Утилитой ssh-keygen сгенерировал пару ключей, они появились в папке моего профиля C:\Users\Roma\.ssh
2) На сервере создал директорию для пользователя nodejs /home/nodejs/.ssh/authorized_keys и положил в нее is_rsa.pub
3) Сделал вдалельцем .ssh и файла пользователя nodejs:users и дал права 700
4) Проверил, что в /etc/ssh/sshd_config строка "PubkeyAuthentication yes" не закомментирована
5) Настроил проброс 22-го порта на виртуальную машину, проверил, что могу зайти через WinSCP (по паролю).

При попытке подключиться командой:
ssh -v localhost

Получаю лог:

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: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com 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
nodejs@localhost's password:

То есть ключ, как я понимаю, отправляется?

Логов авторизации не сервере так и не нашел:
[root@ora19c ~]# 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
[root@ora19c ~]#


В чем может быть проблема?
  • Вопрос задан
  • 5012 просмотров
Решения вопроса 1
SLIDERWEB
@SLIDERWEB
ИТ-Куроводитель
Используйте ssh-copy-id. На современных Windows доступен полноценный Linux.
Как вариант - ssh-copy-id для Windows поставляется с git for Windows.
Можно и вручную сделать то же самое
type $env:USERPROFILE\.ssh\id_rsa.pub | ssh {IP-ADDRESS-OR-FQDN} "cat >> .ssh/authorized_keys"

И да, authorized_keys - это файл.
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
vesper-bot
@vesper-bot
Любитель файрволлов
> ) На сервере создал директорию для пользователя nodejs /home/nodejs/.ssh/authorized_keys и положил в нее is_rsa.pub

authorized_keys это файл, а не каталог, и нужно содержимое id_rsa.pub в него (за/до)писать.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы