Setting SSH on a machine using security file for direct ssh
Client:- The system from which the ssh session will be started via the ssh command
Server:- The system that the ssh session connects to
Steps to taken on the client :
On the client run the following commands:
- $ mkdir -p $HOME/.ssh
- $ chmod 0700 $HOME/.ssh (set the security on .ssh folder)
- $ ssh-keygen -t rsa -This should result in two files, $HOME/.ssh/id_rsa (private key) and $HOME/.ssh/id_rsa.pub (public key).
- Copy $HOME/.ssh/id_rsa.pub to the server.
- On the server run the following commands: $ cat id_rsa.pub >> $HOME/.ssh/authorized_keys2
$chmod 0600 $HOME/.ssh/authorized_keys2
Depending on the version of OpenSSH the following commands may also be required:
$ cat id_rsa.pub >> $HOME/.ssh/authorized_keys
$ chmod 0600 $HOME/.ssh/authorized_keys
An alternative is to create a link from authorized_keys2 to authorized_keys:
$ cd $HOME/.ssh && ln -s authorized_keys2 authorized_keys
On the client test the results by ssh'ing to the server
$ ssh -i $HOME/.ssh/id_rsa server
(Optional) Add the following $HOME/.ssh/config on the client:
Host server
IdentityFile ~/.ssh/id_rsa
This allows ssh access to the server without having to specify the path to the id_rsa file as an argument to ssh each time.