Shell script to add keys to ssh config file

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.

 

#!/bin/bash
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`
host $HOSTNAME
hostname $IP
port $PORT
user $USERNAME
IdentityFile ~/.ssh/$KEYNAME
EOF
cat ~/.ssh/config

Leave a Reply

Your email address will not be published. Required fields are marked *