Saturday, March 14, 2009

.ssh/config

ssh reads configuration information from a config file
(if you have one) before connecting to a machine.

This way you can tell ssh how you want to connect toparticular machines. If you have a lot of different
machines that you connect to,  especially if youconnect to them on different ports and with different
user names then
it is a great idea to create the following file
.ssh/config

type vi .ssh/config

and popultate the config file with the information
of the machines that you connect to.
eg
Host *netaxiz.com
Port 2222
User clive
    
Host ipcop1
Port 222
User root
Host home
Hostname 192.168.0.10
User clive
Port 768

with the above information in the config file if you typessh machine.netaxiz.com
will be the equivalent of typing
ssh -p 2222 clive@machine.netaxiz.com

and typing scp file1 ipcop1:file1
will be the equavelent of typing 
scp -P222 file1 root@ipcop1

as you can see the config file can save you a lot of time.

The port and the username from the config file will
automatically be used every time you connect to the
machines listed in the config file.
Were this is especially usefull is when you want to
copy ssh keys to a remote machine using the
ssh-copy id command when the remote machine uses
a different port to 22.

Lets say you want to copy your public keys to your
machine called home but machine home only allows
 ssh connection on port 768. By adding in the information
above for machine home. I can now simply type
ssh-copy-id -i ~/.ssh/id_rsa.pub home
to transfer the keys.

if you get the following error when using ssh
Bad owner or permissions on .ssh/config
then you must change the permissions of the config file.
cd .ssh
chmod 600 config


No comments: