0

I got a server and I want all my users to access using their private key.

  • Users generate with ssh-keygen -t rsa a couple of public and private key. I'm given the public key, with format:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDe++u83PipzF1YmdJ0/OI2ivt/lR7IED5gQ+IBuN97vayfazKKV8+NAGI3o+Qh1f7kCQk3J9km/9tIAPpWZQWZg95aPwkmx4QuYoI7kn/LLaOYtTgaAqU0z9TzP8k83Sth5D3ET4LnkNrfKUhiPQsN1+WnhRafEv3Hu3+mHU7d8KGVyI7yhRoGWFrmPGwobza0bDsjDrSo70TCcMja8UgUTabukUmF3oj92tVKQZ+doNn4x1084rPKfky+5WGXbcuXTZnmWZRDOMqHsXicXp2m0x26oYJ0lTUnAKzWt25t2weKn24ynZzBEFRJi8ndWG+BKFiQsbSlS8ntWtJ7+9vf test@test-PC

Now in the server, I've created an account called test and I would like to Authorize such public key with user test.

I have already set within sshd_config lines:

Protocol 2
Match User root
    PasswordAuthentication no
Match Group foreigners
    PasswordAuthentication no
Match all

AuthorizedKeysFile      .ssh/authorized_keys``

Should I now insert within authorized_keys file the public key? If so, how can I bind such key with its desired user (test)?

2 Answers 2

4

You need to copy/append the public key of everyone who should access the account test to the authorized_keys file for this user, which usually is located in ~/.ssh/authorized_keys (where ~/ expands to the home directory, again usually /home/test/).

That's all there is to be done.

5
  • I am using in /home/test, mkdir .ssh to create such dir, but it says that the file already exists. I am executing after that ls -l and nothing appears... Is that normal? What sould I do? Thank you.
    – TDRS
    Mar 13, 2018 at 17:26
  • @TDRS file/directory names that start with a period (.) are considered hidden files. To see them with ls you need to use ls -a or ls -A
    – ivanivan
    Mar 13, 2018 at 17:27
  • Yes, this is normal. The directory is named .ssh. By default, files and directories with a leading dot in their file name are not displayed by ls. Use ls -la.
    – Sven
    Mar 13, 2018 at 17:27
  • Oh I have just noticed that by creating touch .ssh/authorized_keys. Thank you.
    – TDRS
    Mar 13, 2018 at 17:28
  • I'm using Alpine Linux, and neither /var/log/secure nor /var/log/auth.log exists... How can I see people who access via ssh in alpine linux? Thank you.
    – TDRS
    Mar 13, 2018 at 18:01
-2

Here is what I would do :

  • Once your users have already created their public / privates key thay have to run the command bellow in order to export their public key to the server.

    ssh-copy-id username@ip_address
    
  • On the server you have to modify your /etc/ssh/sshd_config file and add the following

    Match User username
            AuthenticationMethods publicKey
    
  • If it is for all users just put the AuthenticationMethods publicKey statement

  • Then restart sshd service and it should work

Cheers

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .