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 id_rsa.pub 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/id_ras.pub pi@<ip address>

# from github
sshssh-import-id-gh

Create a key pair

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

copy the key to the remote server

ssh-copy-id -i ~/.ssh/some-key.pub server_ip_address
ssh-copy-id -i ~/.ssh/some-key.pub -p 2222 root@192.168.1.10 

running ssh-agent

eval $(ssh-agent)

remember ssh key password

vim ~/.ssh/config

Add following to the ssh config file

AddKeysToAgent yes

Tags:

Categories:

Updated:

Comments