Home > Mobile >  How can I enable ssh key authentication on the user account of a linux server?
How can I enable ssh key authentication on the user account of a linux server?

Time:03-22

I just rented a VPS with zap hosting and I am trying to protect my server with public key authentication. I think I have set it up properly, if I type ssh root@<server ip> it logs me in straight away using the ssh key. However, if I log into the server using just ssh <server ip>, it asks for my usernames password. How can I make it so that the user account also does SSH-Key authentication?

Thanks in advance

CodePudding user response:

When you ssh to machine b from UNIX-like (Linux, FreeBSD) machine a without giving a username (root@) ssh presents your username from machine a to machine b.

To configure your user account on machine b to use your public key,

  • make sure machine b has a user with the same name as the one you use on machine a.
  • log in to machine b with your user account.
  • create the directory called .ssh in your account's home directory.
  • put your public key or keys into .ssh/authorized_keys

Or, easier, if you have a Github account with a public key.

  • log in to machine b with your user account.
  • Run ssh-import-id-gh <username> where <username> is your Github username.

CodePudding user response:

On your local machine add the following to your SSH config (this is usually located at ~/.ssh/config. You may need to create the file if it does not already exist.

Host <server ip>
    HostName <server ip>
    User <your remote user name>
    IdentityFile <Path to private key>

On the server,login as the user you want to ssh in as and append the contents of your public key to the file located at ~/.ssh/authorised_keys

  • Related