Simply Log in Remote Servers with Config File
I always have trouble remembering various passwords. Also, it is trouble keying passwords everytime login remote servers. Recently, I find it convenient connecting servers by using SSH config file.
To make things simple and clear, suppose a user with following information”
|
|
With Passwords
Previously, what I do to connect a remote server
|
|
It is not too bad when only one server is used. Image when you got three or more servers…
Free Login
But now, we can make it simpler and more secure by using public/private key pairs.
Edit config file
Enter path /.ssh from local root path. There is a file named config, if not, create one. Enter the SSH config file, it should look like:
Firstly, enter path ~/.ssh
. There should be a file name config
where the content is like:
|
|
Generate key files
What we need to do next is to generate the public/private key pair.
To generate key pairs, we type command
|
|
Then it will ask you to enter the file name to save the key and enter the passphrase, you can name the file as an alias name , example
in this case, and leave passward as empty. Once the files are generated, there are two new files named example
and example.pub
.
Configurate sever
Subsequently, copy public key file from local to remote server and copy public key to the file authorized_keys.
|
|
Then, execute following commands to get permission
|
|
Note that if the path /.ssh
or the file authorized_keys
do not exist, then create them. All of above operations should be done in server.
Config local config file
Then we fill our own information like:
|
|
Test
Now, you are able to connect the remote server without keying passwords.
ssh example
That’s it. In the future, if you have new server, add information about the server in config
file and follow above instructions.
This totally makes my day.