Using Terminal To SSH

You can use FTP, SFTP and even SSH using username and password but SSH can also be done via key based authentication via terminal. I want to document this for myself and others as this is pretty helpful in my job as a support engineer.

Saving the key!

First, you’d need to obtain the key and save it on your desktop. You can just save it without any extension, that’s okay. Next make sure to set it’s permissions to read only else it’d return an error as follows –

To avoid that error, make sure to run this command: chmod 400 key where key is your file name.

Logging in via Terminal

  • The command to connect is: ssh username@host -i <path to key>.
  • That should get you logged in where you can look around
  • using change directory cd command,
  • see your present working directory using pwd
  • and edit files using nano <filename>.

In case you see permission denied error while editing a file, you can always use sudo command. For example sudo nano <filename> and that’ll do.

Once you’re done editing, you can escape the file by ctrl+x and when you’re done with the session, you can quit using the exit command.

That’s all in this post! 🙂