Linux: Как настроить authorized_keys, чтобы войти в систему под другим пользователем

282
Greg Dougherty

локальный идентификатор пользователя: GregD идентификатор удаленного пользователя: GregTD

Я знаю, как настроить authorized_keys, чтобы я мог войти в систему как GregD. но мне нужно подключиться к серверу как GregTD, и, несмотря на то, что я добавил мои авторизованные_ключи в .ssh / (да, у меня правильно установлены разрешения), и даже после успешного запуска ssh-copy-id, меня все равно спрашивают пароль когда я пытаюсь ssh GregTD @ foo

Список удаленных .ssh:

GregTD@foo $ ls -alh total 32K drwx------+ 2 GregTD GregTD 4.0K Mar 29 10:53 ./ drwxrwxr-x+ 6 GregTD GregTD 4.0K Mar 29 10:52 ../ -rw-------+ 1 GregTD GregTD 398 Mar 29 10:53 authorized_keys lrwxrwxrwx. 1 GregTD GregTD 15 Mar 29 10:31 authorized_keys2 -> authorized_keys -rw-rw-r--+ 1 GregTD GregTD 188 Mar 29 10:18 known_hosts 

Листинг моего .ssh:

$ ls -alh ~/.ssh/ total 200 drwx------ 16 GregD GregD 544B Mar 29 10:53 ./ drwxr-xr-x+ 184 GregD GregD 6.1K Mar 26 09:37 ../ -rwx------ 1 GregD GregD 2.1K Feb 28 12:09 authorized_keys* -rwx------ 1 GregD GregD 679B Feb 28 12:09 config* -rw------- 1 GregD GregD 1.7K Feb 28 12:09 github_rsa -rw-r--r-- 1 GregD GregD 401B Feb 28 12:09 github_rsa.pub -rw------- 1 GregD GregD 1.6K Feb 28 12:09 id_rsa -rw-r--r-- 1 GregD GregD 398B Feb 28 12:09 id_rsa.pub -rwx------ 1 GregD GregD 47K Mar 19 21:15 known_hosts* 

Что я сделал:

$ ssh-copy-id GregTD@foo /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/GregD/.ssh/id_rsa.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys GregTD@foo's password:   Number of key(s) added: 1  Now try logging into the machine, with: "ssh 'GregTD@foo'" and check to make sure that only the key(s) you wanted were added.   $ ssh -v GregTD@foo OpenSSH_7.4p1, LibreSSL 2.5.0 debug1: Reading configuration data /Users/GregD/.ssh/config debug1: Reading configuration data /etc/ssh/ssh_config debug1: Connecting to foo [10.146.103.127] port 22. debug1: Connection established. debug1: identity file /Users/GregD/.ssh/id_rsa type 1 debug1: key_load_public: No such file or directory debug1: identity file /Users/GregD/.ssh/id_rsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /Users/GregD/.ssh/id_dsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /Users/GregD/.ssh/id_dsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /Users/GregD/.ssh/id_ecdsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /Users/GregD/.ssh/id_ecdsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /Users/GregD/.ssh/id_ed25519 type -1 debug1: key_load_public: No such file or directory debug1: identity file /Users/GregD/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_7.4 debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4 debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000 debug1: Authenticating to foo:22 as 'GregTD' 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: aes128-ctr MAC: hmac-sha2-256 compression: none debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha2-256 compression: none debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: A key debug1: Host 'foo' is known and matches the ECDSA host key. debug1: Found key in /Users/GregD/.ssh/known_hosts:124 debug1: rekey after 4294967296 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: rekey after 4294967296 blocks debug1: SSH2_MSG_EXT_INFO received debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512> 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 RSA public key: /Users/GregD/.ssh/id_rsa debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password debug1: Trying private key: /Users/GregD/.ssh/id_dsa debug1: Trying private key: /Users/GregD/.ssh/id_ecdsa debug1: Trying private key: /Users/GregD/.ssh/id_ed25519 debug1: Next authentication method: password GregTD@foo's password:  

Запустил ssh -vv дважды, один раз как GregTD (неудача), и один раз как GregD (успех)

Было два различия: Не удалось:

debug1: rekey after 4294967296 blocks debug2: key: /Users/m082166/.ssh/id_rsa (0x7fef96e12320) 

Успех:

debug1: rekey after 4294967296 blocks debug2: key: /Users/m082166/.ssh/id_rsa (0x7fb600e0a420) ... debug1: Offering RSA public key: /Users/m082166/.ssh/id_rsa debug2: we sent a publickey packet, wait for reply debug1: Server accepts key: pkalg rsa-sha2-512 blen 279 

2-й успех (хотел посмотреть, изменился ли ключ. Он сделал):

debug2: key: /Users/m082166/.ssh/id_rsa (0x7fb600e0a420) 

Это полезно? То, что я пытаюсь сделать, должно работать, да?

0
Что такое содержимое `/ Users / GregD / .ssh /`? Ваш закрытый ключ читается оттуда и, кажется, отсутствует: `Нет такого файла или каталога`. yahol 6 лет назад 0
Может потребоваться поиск в `/ var / log / auth.log` или` / var / log / dmesg` в удаленной системе. LawrenceC 6 лет назад 1
"debug1: key_load_public: нет такого файла или каталога" ищет файл сертификата для ключа. Что не нужно, так как в противном случае ни один из моих других удаленных входов в систему не будет работать. Я добавил ls для моего .ssh Greg Dougherty 6 лет назад 0
Ты прав, моя ошибка. Добавление к комментарию @ LawrenceC: также `/ var / log / secure` на CentOS / RHEL / Fedora-подобных системах. Будет ли увеличение детализации отображать сообщение после "Предложение открытого ключа RSA ..."? yahol 6 лет назад 0
Как я могу увеличить многословие? К сожалению, не существует ни auth.log, ни dmesg, а secure может быть прочитана только пользователем root, а я не являюсь Greg Dougherty 6 лет назад 0
Вы можете увеличить детализацию до 3 уровней: `-v`,` -vv`, -`vvv`. Попробуйте сначала с `-vv`, так как он дает интересный вывод. yahol 6 лет назад 0
Запустил его с -vv, добавил результаты Greg Dougherty 6 лет назад 0
Возможно, есть странное взаимодействие с LibreSSL и openSSL, если ваш sshd связан с OpenSSL. Убедитесь, что ssh и sshd имеют одинаковую версию. LawrenceC 6 лет назад 0
@LawrenceC У меня есть две учетные записи на сервере, одна GregD одна GregTD. Я могу соединиться с моей парой открытый-закрытый ключ так же хорошо, как GregD. У меня только проблемы с подключением к GregTD Greg Dougherty 6 лет назад 0

0 ответов на вопрос

Похожие вопросы