How to create SSH keys

Setting up SSH keys allows automatic scripts to deploy websites between servers. This is extremely helpful and eliminates the need to use an FTP program. Following is the code we use to setup our SSH keys

Traverse to your home ssh directory on your development server.

# traverse to your ssh directory cd ~/.ssh/

Next we create our keys.

# create your ssh key ssh-keygen -t dsa

Just hit return 3 times to create the keys and also create them without a password

Enter file in which to save the key (/var/www/.ssh/id_dsa): Enter passphrase (empty for no passphrase): Enter same passphrase again:

Now that our keys are created, we need to transfer them to the other server. Replace user with your username and remote_server with the server address that you want to transfer the key to.

# copy key to remote server scp ~/.ssh/id_dsa.pub user@remote_server.com:.ssh

Once we have our keys transferred to our remote server, we need to login to the remote server and add the key to the authorized_keys file.

# login to remote server and add key to authorized_keys file ssh user@remote_server.com cd .ssh cat id_dsa.pub >> authorized_keys

Now we have our keys on both servers and added to our authorized_keys files. This will enable us to transfer files automatically without passwords.