Generating public/private ssh keys

How to generate and use public / private ssh keys

This guide is tested on Centos 6
To generate RSA ssh key pair enter following command:

ssh-keygen -t rsa

To generate DSA ssh key pair enter following command:

ssh-keygen -t dsa

You will be prompted to specify a path to locate the keys

[root@localhost ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):

You can specify it or just press "enter" to accept default location.
Now you have the keys generated. The keys are id_rsa and
Copy to remote host(s) in user directory, for example /home/alex/.ssh/ or ~/.ssh, and rename it to authorized_keys. Copying can be done with scp:

scp alex@

If you have an issue like "command not found" install ssh clients on both sides entering:

yum install openssh-clients

Now open /etc/ssh/sshd_config on remote host and set following attributes:

RSAAuthentication yes
PubkeyAuthentication yes 
PasswordAuthentication no

Restart ssh service

/etc/init.d/sshd restart

To add one more public key to remote host simply append the key to existing authorized_key manually or using command:

cat ~/.ssh/ >> ~/.ssh/authorized_keys

If you can't get why it doesn't work make sure you have selinux disabled


Was this answer helpful?

 Print this Article

Also Read

Create OpenVPN client

The following instructions are for those VPSGet customers who have installed OpenVPN...


How to install nginx on Centos Add nginx repo first. To add it, create the file...

Security tips for Linux server

1. Use only  strong passwords for all accounts , especially for root. Always use a secure root...

Changing ssh port

How to change ssh port. Open the file /etc/ssh/sshd_config with your favourite text...

Sendmail [25: Connection refused] fix

If you can't receive email from the outside and got next error:  (Delivery Status Notification...