SSH Commands

less than 1 minute read

In this post we will look at how to use ssh key-based login.

Generate SSH key pair

ssh-keygen -t rsa -b 4096

SSH into the destination server and add the content of to remote server authorized_keys file

vim authorized_keys

If .ssh directory or .ssh/authorized_keys file is not available, follow the below instructions to create them,

create .ssh directory

vim authorized_keys

Set the right permissions

chmod 700 ~/.ssh

Create the authorized_keys file

touch ~/.ssh/authorized_keys

Set the right permissions

chmod 600 ~/.ssh/authorized_keys

Source1, Source2

How to generate a key pair in MobaXterm? Enter the following command in the MobaXterm terminal

ssh-keygen -t rsa -q -f ~/.ssh/id_rsa

This will generate the private and public key pair inside .ssh folder located in your home directory (source).

Copy ssh key to remote machine

#from local machine
ssh-copy-id -i ~/.ssh/ pi@<ip address>

# from github

Create a key pair

ssh-keygen -t ed25519 -C "some-label"

copy the key to the remote server

ssh-copy-id -i ~/.ssh/ server_ip_address
ssh-copy-id -i ~/.ssh/ -p 2222 root@ 

running ssh-agent

eval $(ssh-agent)

remember ssh key password

vim ~/.ssh/config

Add following to the ssh config file

AddKeysToAgent yes