Friday, July 28, 2023

How to set up ssh to login remote host

 ssh config file facilitates remote access.  In a config file you can specify an alias for the host, identify its IP address, identify the userid you are logging in with, and most importantly indicate and identity file that will save you from entering/remembering your password each time you want to ssh to the host.

  •  create a public/private key for the host

On your machine run 

  >ssh-keygen

Enter the file to which to save the key.  Usually I create/save all my ssh id files in my home directory under directory called .ssh

The dot preceding ssh makes the directory hidden.  You can see the hidden files and directories by passing -a option to the ls command.

   >ls -a

  • copy the ssh public file to the host

   >ssh-copy-id -i ~/.ssh/my-host-key user@host

  • create and populate the config file

  >vi ~/.ssh/config

  Host my-host

    HostName IP-Address

    User    JoeDoe

    IdentityFile ~/.ssh/my-host-key


  •  remote login using ssh

  >ssh my-host


  You don't need to pass user@host  <<HostName and User entries of config file>> 

  You don't need to pass password        <<IdentityFile entry of config file>> to ssh


Any questions and/or problems setting this up, you can let me know in the comments.


Later