If you happen to have more than one SSH session that you need to use on a regular basis or happen to have various identities one of the easiest ways to manage them is by using a config file. In this case the file is going to be ~/.ssh/config (you can use /etc/ssh/ssh_config to make options available to all users on the system).
Important! When using a config file make sure you place your most specific information (i.e. hosts, etc) at the beginning of the file. SSH takes the first matching directive and will ignore any further down the file.
In my use, the options used have been fairly limited to the Host, HostName, User and Dynamic and Local Forwards, X Forwarding and TCPKeepAlive.
An example of an entry is:
LocalForward localhost:9091 remotehost:9091
If you manage multiple servers or hosts and are required to used different identities when connecting a config file can make life a lot easier as you can specify what identity to use with the “IdentityFile” variable. Using this you can specify what key file to use on a per-host or network basis. Wildcards make this easier.
From the ssh_config manpage:
A pattern-list is a comma-separated list of patterns. Patterns within pattern-lists may be negated by preceding themwith an exclamation mark (‘!’). For example, to allow a key to be used from anywhere within an organisation except from the “dialup” pool, the following entry (in authorized_keys) could be used:
If you have used a config file make simplify your host access let me know in the comments