Your personal SSH Configuration

From docwiki
Jump to: navigation, search


Motivation

If you use ssh often then always typing long host-names or even remembering IP address is tedious. This is the time when you should start creating your own .ssh/config

Where do you find configuration files?

Configuration files for system wide programs are below /etc. Since ssh has a lot of configuration files they have chosen to put them into their own directory /etc/ssh. The configuration for your ssh client is in /etc/ssh/ssh_config while the configuration for your sshd (d for daemon - the server process) is in /etc/sshd_config and they key files can also be found in that directory.

For programs that are used by users it is necessary to have a config file for each user. Per convention the programs put their configuration files in your home directory with filenames that begin with a dot. dot-files are not shown with the ls command, unless you use ls -a.

Again: since ssh has a lot of config files they use their own hidden directory. .ssh Your ssh directory might look like this:

$ ls -1 ~/.ssh
authorized_keys
config
id_rsa
id_rsa.pub
known_hosts

the config file holdes the config. id_rsa is the private key if you use Public Key Encryption and id_rsa.pub is the public part. The file known_hosts holds the entries for the fingerprints of the hosts that you have already connected to and authorized_keys holds the public keys that are allowed to connect without password.

Your .ssh/config


Host wu
HostName pecuchet.wu-wien.ac.at
User h77123456

Host myweb
HostName 10.1.2.3
User root

The first entry would create a shorthand named wu to login to the pecuhet host with the username h77123456. This is convenient if you have a different user name at your own maschine. The second entry will create an alias named myweb for a maschine with the IP 10.1.2.3

If you have created the above entries you can then use the shorthand. e.g. like that:

$ ssh myweb
$ ssh wu
$ scp -r diplomarbeit wu:
$ scp -r myweb:/var/www/mysite /tmp/

If you already use public-key login then you will not even need a password anymore. See: https://linux.die.net/man/5/ssh_config


Exercises

Create a .ssh/config file and add an alias entry for a host that you use to login.