Using SSH keys in Linux/en: Difference between revisions

Jump to navigation Jump to search
Updating to match new version of source page
(Updating to match new version of source page)
(Updating to match new version of source page)
Line 33: Line 33:


=Connecting using a Key Pair=
=Connecting using a Key Pair=
Once your key pair has been created copy the public key (the <code>/home/ubuntu/.ssh/id_rsa.pub</code> key file in the above on your local machine) to the <code>/home/USERNAME/.ssh/authorized_keys</code> file on the server you wish to connect to. If you had to create the file <code>/home/USERNAME/.ssh/authorized_keys</code> ensure the file <code>authorize_keys</code> and directory <code>.ssh</code> have the correct permissions with <code>chmod 600 ~/.ssh/authorized_keys</code> and <code>chmod 700 ~/.ssh</code> respectively.
<ol>
 
<li>Once your key pair has been created, copy the public key (the <code>/home/ubuntu/.ssh/id_rsa.pub</code> key file in the above on your local machine) to the <code>/home/USERNAME/.ssh/authorized_keys</code> file on the server you wish to connect to. If the <code>authorized_keys</code> file already exists add your public key as a new line at the bottom of the file using an editor such as vim or nano.</li>
Finally test the new key by sshing to the remote machine from the local machine with
<li>Ensure the file <code>/home/USERNAME/.ssh/authorized_keys</code> and directory <code>/home/USERNAME/.ssh/</code> have the correct permissions with <code>chmod 600 /home/USERNAME/.ssh/authorized_keys</code> and <code>chmod 700 /home/USERNAME/.ssh</code> respectively.</li>
 
<li>If you were not logged in as <code>USERNAME</code> while you were creating this <code>authrorized_keys</code> file (e.g. you had administrative privileges on the server and used the <code>sudo</code> command before the above commands), ensure the owner of the directory <code>/home/USERNAME/.ssh</code> and the file <code>authrorized_keys</code> are owned by the user <code>USERNAME</code> with the commands <code>sudo chown USERNAME:USERNAME /home/USERNAME/.ssh</code> and <code>sudo chown USERNAME:USERNAME /home/USERNAME/.ssh/authorized_keys</code>.</li>
<source lang="console">
<li>Finally test the new key by sshing to the remote machine from the local machine with
[name@server]$ ssh -i /home/ubuntu/.ssh/id_rsa USERNAME@ADDRESS
<source lang="console">[name@server]$ ssh -i /home/ubuntu/.ssh/id_rsa USERNAME@ADDRESS</source>
</source>
where <code>/home/ubuntu/.ssh/id_rsa</code> specifies your private key file and <code>USERNAME</code> is the user name on the remote machine, and <code>ADDRESS</code> is the address of the remote machine. If you have administrative access on the server and created the account for some one else, rather than giving you their private key they should keep the private key and test the connection out themselves. Private keys should remain private.
 
</li>
where <code>/home/ubuntu/.ssh/id_rsa</code> specifies your private key file and <code>USERNAME</code> is the user name on the remote machine, and <code>ADDRESS</code> is the address of the remote machine.
</ol>
 
[[Category:Connecting]]
[[Category:Connecting]]
38,760

edits

Navigation menu