Managing multiple ssh keys CentOS / Linux based OS or Mac OS


If you are admin or developer you have encountered ssh in your life. Ssh stands for Secure Shell which let you login to pc / server remotely and securely. It replaces telnet, rlogin etc… which does the same but does not provide security.

For ssh to work we need to generate keys using ssh-keygen command on mac or linux base system. For windows putty or like wise software is used. In some cases like Amazon keys are provided and we need to download the same. Keys are used to make connection.
This post shows how to manage multiple ssh keys on the pc.
Managing multiple ssh keys CentOS

Scenario: Being an admin or a developer there are chances that you need to connect to different servers to perform routine tasks or other stuff and need to provide respective keys during connection.
Simple way to do this run ssh command like ssh –i location_of_key dummy@customdomain.com, a very simple but difficult when you have many keys and many username.

To manage the ssh keys and other details config file can be created, where we can specify host, user and the key to be used for specific host.

Than while connecting the host we can simply type ssh easyuserfriendly name as configured in the config file.

Usually keys are stored in .ssh directory which is located in home directory in most of  MAC or Linux base operating system.

To manage this we can use config file in .ssh directory which will store all such data. The config file will contain entry for host, hostname, path or location to the keys file generated using the ssh-key gen command or obtained from remote pc.

Following is the sample config file.
----------------------------
  
Host mysite
    HostName       test.somedomain.com
    IdentityFile   ~/.ssh/id_rsa_testsomedomainkey
    User           admintest

Host myaws
    HostName      ec2-ab-cde-fgh.us-west-9.compute.amazonaws.com
    IdentityFile  ~/.ssh/aws_instance.pem
    User          ec2-user

------------------------------
To connect now simply use ssh mysite, it will look in to config file for key location, hostname and user.

Labels: , ,