Indeed, I want to create another new guide for how to access a remote server using Public-Key Authentication. Why? Basically: I want to use my blog as a technology notebook for my own.
So, Let’s ask, Do you want to connect to your remote server through ssh without having to authenticate every time?. If the answer is yes, follow these steps:
Notes
- This setup is based on Ubuntu 11.10
- For this demo username is le-user and server name le-server.com
Step 1
Create a public/private key for your hosting server in your local computer. In a terminal go to you .ssh
folder and execute ssh-keygen
.
- For the question Enter file in which to save the key, enter this name le-server.com.key or whatever name you like.
- For questions related to passphrase, leave it in blank, only hit enter.
1 | luis@myblog:~$ cd .ssh |
Step 2
Copy generated key to your hosting server. Execute ssh-copy-id -i le-server.com.key le-user@le-server.com
. (It will prompt you to enter your hosting user password)
1 | luis@myblog:~/.ssh$ ssh-copy-id -i le-server.com.key le-user@le-server.com |
Step 3
In your computer, in the folder .ssh open or create a filename called config and add the following peace of code at the end of the file
1 | Host le-server.com |
Step 4
Execute ssh-add ~/.ssh/le-server.com.key
. This will add the private key to the SSH agent so that you will be prompted for the passphrase only once.
Step 5
From your local computer. Open a terminal and just type ssh le-server.com
and voila!
1 | luis@myblog:~$ ssh le-server.com |
Happy coding :D