Rotten mud: Learning ssh key portable, ssh key
This article is written by Xiuyi Lin FengProviding friendship sponsorship, first launched in the dark world
In the previous article, "Learn ssh without password", we explained how to use an ssh key to log on to the server without a password.
This article explains how to carry generated keys with you.
For detailed steps on how to generate an ssh key, see the previous article "Learn ssh password-less login".
1. Generate a key
Now we use xshell to generate a key. Note: in this chapter, I will only proceed without further instructions.
As follows:
Now we have the public key and private key: id_dsa_150518.pub and id_dsa_150518. Upload the Public Key id_dsa_150518.pub to the ilanni user directory of the server 192.168.1.9 to be connected. As follows:
Ifconfig eth0 | grep 'inet addr '| awk' {print $2} '| cut-d:-f2
Cat. ssh/authorized_keys
Now we can carry this key id_dsa_150518 with you, and connect to the 192.168.1.9 server wherever you are.
Note: The key we are talking about now is actually the ssh Private Key generated by xshell above.
Note that the private key id_dsa_150518 can carry the private key file or copy the content of the private key to other files. As follows:
Note: The content of the ssh private key is being copied and cannot contain any character.
2. Connecting to the ssh server in windows
Assume that the OS we use is windows, and the ssh private key is around us. Then we can use this private key to connect to the ssh server.
Here, we will explain how to use xshell to connect to the ssh server. Of course, you can also use other ssh client software for connection.
Run the following command to connect to the ssh server:
Ssh ilanni@192.168.1.9
In this case, the xshell window will pop up asking you to enter your password. As follows:
We do not select the Password option, but select the Public Key option. Then select Browse> file as follows:
Find the ssh private key file id_dsa_150518, as shown below:
Select the private key file as follows:
We can see that when we connect to the 192.168.1.9 server, xshell does not prompt us to enter the password.
Note: The token is saved.
When connecting the sshserver to select a secret file, you only need to select the ilanni.txt file.
3. Connect to the ssh server in linux
In chapter 2, we explain how to connect to the ssh server through the ssh private key in windows. In this section, we will explain how to use the ssh private key to connect to the ssh server in linux.
First, upload the ssh Private Key to the linux host or create any new file on the linux host, copy the content of the Private Key to the file, and then use the following command to connect:
The ssh-I id_dsa_150518 ilanni@192.168.1.9
We can see that you still need to enter the user password to connect to the ssh server 192.168.1.9.
Is our operation incorrect or what is going on?
If you carefully read the above prompt, you will find that this is because the ssh private key user permission is too large to be set and is not secure.
SshFor the sake of security, the permission on the private key file is generally set to 600, that is, the user has read and write permissions on the private key file, the user group and other user groups do not have any permissions on the private key file.
Now we only need to set the ssh Private Key File Permission to 600, as shown below:
Chmod 600 id_dsa_150518
Connect again using the ssh-I id_dsa_150518 ilanni@192.168.1.9 Command, as shown below:
We can see that we have already entered the 192.168.1.9 server without a password.
Note: The-I parameter in the preceding command is used to specify the ssh private key file.
For more information about how to use ssh commands, see the help of ssh. As follows:
Ssh -- help
All the content about the ssh key is complete.