Difference between revisions of "Generating public/private ssh keys"

From vpsget wiki
Jump to: navigation, search
(Created page with "This guide is tested on Centos 6<br/> To generate RSA ssh key pair enter following command: <pre> ssh-keygen -t rsa </pre> To generate DSA ssh key pair enter following command...")
 
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
How to generate and use public / private ssh keys
 +
 
This guide is tested on Centos 6<br/>
 
This guide is tested on Centos 6<br/>
 
To generate RSA ssh key pair enter following command:
 
To generate RSA ssh key pair enter following command:
Line 20: Line 22:
 
scp id_rsa.pub alex@1.2.3.4:/home/alex/.ssh/authorized_keys
 
scp id_rsa.pub alex@1.2.3.4:/home/alex/.ssh/authorized_keys
 
</pre>
 
</pre>
 +
or using ssh-copy-id:
 +
ssh-copy-id user@hostname.example.com
 +
with identity file:
 +
ssh-copy-id -i <identity> user@hostname.example.com
 +
 
If you have an issue like "command not found" install ssh clients on both sides entering:
 
If you have an issue like "command not found" install ssh clients on both sides entering:
 
<pre>
 
<pre>
Line 30: Line 37:
 
PasswordAuthentication no
 
PasswordAuthentication no
 
</pre>
 
</pre>
 +
Restart ssh service
 +
<pre>
 +
/etc/init.d/sshd restart
 +
</pre>
 +
To add one more public key to remote host simply append the key to existing ''authorized_key'' manually or using command:
 +
<pre>
 +
cat ~/.ssh/another_one_id_rsa.pub >> ~/.ssh/authorized_keys
 +
</pre>
 +
If you can't get why it doesn't work make sure you have [http://wiki.vpsget.com/index.php/How_to_disable_selinux selinux disabled]
 +
"[[Category:Linux]]"

Latest revision as of 16:14, 30 September 2014

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 id_rsa.pub.
Copy id_rsa.pub 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 id_rsa.pub alex@1.2.3.4:/home/alex/.ssh/authorized_keys

or using ssh-copy-id:

ssh-copy-id user@hostname.example.com

with identity file:

ssh-copy-id -i <identity> user@hostname.example.com

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/another_one_id_rsa.pub >> ~/.ssh/authorized_keys

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