When you have many servers with different usernames, keys etc, it’s easier to manage the server with the .ssh/config file.

A very basic script that I wrote long time ago to easily add an host to my ~/.ssh/config file.


read -e -p "Hostname to add to  ~/.ssh/config : " -i "" HOSTNAME
read -e -p "IP de l'hote : " -i "" IP
ls -l ~/.ssh/
read -e -p "Key to use  : " -i "~/.ssh/id_rsa" KEYNAME
read -e -p "UserName : " -i "ubuntu" USERNAME
read -e -p "port : " -i "22" PORT
cat >> ~/.ssh/config << EOF
#Added on `date`
hostname $IP
port $PORT
IdentityFile ~/.ssh/$KEYNAME
cat ~/.ssh/config