W
W
WhatIsHTML2018-07-11 15:55:11
SSH
WhatIsHTML, 2018-07-11 15:55:11

Why is the server rejecting the SSH key?

A trivial task turned into a real hell. I want to set up a connection to the server via SSH + password.
It was done step by step:
1. Generated public id_rsa.puband private id_rsakeys on the local computer.
2. On the server, I uploaded the public key to a folder /etc/ssh/
3. On the server, in a folder, I /etc/ssh/create a file configthat looks like this

config
# This is the ssh client system-wide configuration file.  See
# ssh_config(5) for more information.  This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.

# Configuration data is parsed as follows:
#  1. command line options
#  2. user-specific file
#  3. system-wide file
# Any configuration value is only changed the first time it is set.
# Thus, host-specific definitions should be at the beginning of the
# configuration file, and defaults at the end.

# Site-wide defaults for some commonly used options.  For a comprehensive
# list of available options, their meanings and defaults, please see the
# ssh_config(5) man page.

Host *
#   ForwardAgent no
#   ForwardX11 no
#   ForwardX11Trusted yes
#   RhostsRSAAuthentication no
#   RSAAuthentication yes
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   GSSAPIKeyExchange no
#   GSSAPITrustDNS no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/identity
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   IdentityFile ~/.ssh/id_ecdsa
#   IdentityFile ~/.ssh/id_ed25519
#   Port 22
#   Protocol 2
#   Cipher 3des
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
#   MACs hmac-md5,hmac-sha1,[email protected],hmac-ripemd160
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
#   ProxyCommand ssh -q -W %h:%p gateway.example.com
#   RekeyLimit 1G 1h
    SendEnv LANG LC_*
    HashKnownHosts yes
    GSSAPIAuthentication yes
    GSSAPIDelegateCredentials no

Host example
  HostName IP_ADDRESS_OF_THE_HOST
  User root
  IdentityFile ~/.ssh/id_rsa.pub
  Port 22


4. I disconnect from the server and try to connect already with the key. I connect via putty, select private key locally. Putty suggests reformatting the private key to .ppk format, I agree. When I try to connect to the server, I get a message Сервер отклонил наш ключ.. However, I can connect with the password as before.
What did you do wrong?
After changes in a file configdo I need to restart something?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mystray, 2018-07-11
@WhatIsHTML

>What did you do wrong?
all.
for example, firstly, in the /etc/ssh/ folder, you need a server configuration file sshd_config , which is responsible for the operation of the server and has its own parameters, and you slip the client one into it.
Second, id_rsa.pub is renamed to authorized_keys in the specific user's $HOME/.ssh/ folder (or in sshd_config this is edited by the AuthorizedKeysFile parameter for a specific Match or globally).
Thirdly, when sshd_config changes, the server must be restarted / re-read the config.
Fourth, the correct permissions must be set for the files in $HOME/.ssh.

V
Vsevolod, 2018-07-11
@Vantela

On the server, it should look something like this:
mkdir -p ~/.ssh && cat id_rsa.pub >> ~/.ssh/authorized_keys && chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys
as the user you are using are going to come in.
Why are you creating a config file I can not understand.
There should already be a server configuration file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question