SSH login provides two kinds of authentication methods: password (password) authentication method and key authentication method. where password (password) authentication method is one of our most commonly used, here is the key authentication method to log on to linux/Unix.
Using key login is divided into 3 steps:
1. Generate key (public key and private key);
2. Place the public key into the server ~/.ssh/authorized_key file;
3. Configure the SSH client to log in using the key.
First, generate the key public key and private key (private key)
Open Xshell, click "Tools" in the menu bar and select "User Key Generation Wizard ..." In the popup menu, such as:
Pop up the "User Key Generation Wizard" dialog box, select "RSA" Public key encryption algorithm in the "Key Type" key, "Key Length" is selected as "2048" bit key lengths, such as:
Click "Next" and wait for key generation:
Proceed to the next step, enter the file name of key in "Key name", I Am "key" here, enter a password in "Passphrase" to encrypt the private key, and enter the password confirmation again, such as:
Click "Next", the key generation is complete (Public key format Select SSH2-OPENSSH format), here is the key, we can copy the public key and then save, you can also directly save the public key to the file, such as. The private key is not shown here and can be exported to a file in "User Key mangager ...":
Click the "Save as File ..." button to save the public key to the disk, with the file name "Key.pub" and alternate.
Second, upload public key to the server:
Log on to the server with Xshell, go to the "/root/.ssh/" directory, run the RZ command (if you do not have the RZ command, run the yum install Lrzsz installation), send the key.pub to the server, and then run the following command to set the public key ( Public Key) into the "Authorized_keys" file:
- [Email protected] ~]# cd/root/.ssh/
- [email protected]. ssh]# RZ
- RZ waiting to receive.
- [email protected]. ssh]# Cat me.pub >> Authorized_keys
- [email protected]. ssh]# chmod Authorized_keys
- [email protected]. ssh]# ls
- Authorized_keys known_hosts me.pub
- [email protected]. ssh]# Cat Authorized_keys
- Ssh-rsa aaaab3nzac1yc2eaaaabiwaaaqea4vcowfrarc1m3mfeal50v2z2siavo3ijpr/lz00ezah8ejfzhqjac/ Agkljyxmngpvdprdtlyco8h3p5vegxoegkcx74fdym0vndvabvd1xsd8elnyltccnk7rzjbi3htjox3q1n0vnmmb5d20d9occkax4ac94rwns33ec5cszntmg ain+uzl0flqkls1osywfahstwya6b33qg7y5e4b6j/caobnpx6egtbrgi97gxjhzwyylgrpwmuuhpqs5xtorb08cvxayzewtq1mxv0p+ Po4l1pbhlrf+tsoz5rsbzzjy4/jmazdxhntnayo0j0vngbbxkucnsahz
Third, configure Xshell to log on to the server using the key authentication method:
Open Xshell, click the "New" button, pop up the "New Session Properties" dialog box, in the "Connection" column, enter the IP address and port that you just configured the public key, as shown in:
Click on the Left "authentication", switch to the authentication section, in the "Method" select "Public Key" authentication, the user name input "root" (the public key is placed in the root directory in the. ssh folder), in "User Key" Select the private key that we just generated, "key", and "Passphrase", enter the encryption password for the private key.
Click OK, xshell configure SSH password-free login configuration complete.
Appendix: Linux Ssh-keygen command generates key:
In fact, under Linux Ssh-keygen can also generate a key, under Linux input ssh-keygen-t RSA, at the prompt, enter the name of the key (here is key) and the private key encryption password, both complete the key generation. Of the two files generated, "Key" is the private key, "Key.pub" is the public key. As shown in the following:
Xshell Configuring SSH Password-free login-key public key and private key login