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:
Continue 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 (password arbitrary input), and re-enter the password confirmation, 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]. ssh]# RZ [[email protected]. ssh]# ls[[email protected]. ssh]# ls[[email protected]. ssh]# rz[[email protected]. ssh]# LSKEY.PU B[[email protected]. ssh]# lskey.pub[[email protected]. ssh]# lskey.pub[[email protected]. ssh]# Cat Key.pub>>Authorized_keys[[email protected]. ssh]# lsauthorized_keys key.pub[[email protected]. ssh]# chmod -Authorized_keys[[email protected]. ssh]# lsauthorized_keys key.pub[[email protected]. ssh]# Cat Authorized_keysssh -dss aaaab3nzac1kc3maaaebaldte54j+lfizhi2lim7g3himkoxcj2gnmmqhosqcg2gpmny0onodoewdiszoh/ 8vgxeuerahybixe0ytvrxvrxjx6fkcbzgwhliiorqm+crfcd/vjk8fr/ o1d9pt16a9giyebsunfvaad6cc1pnxzxcmmuqbfk48vocvnhvccohrx2khkazpqmdxogadfmqz4xaibqzh+ fluc1xpyshvcjftkafpfqh3sxvh4vj75d6mjfqgjcnejm1mwpqmmkkjlg+w/uafsg7myrp19+ 2mif7ip527mdiem18fiwi7nkoueuxels0ejal6kk9j1ouwqzqrfblplkria5m2fdco0eaaaahanbdu7g54qxccyk5uwnaebljvfpypf9h14mb+ od8gqqdaaabaqczixc5ha8moces3s442qstuniya2bnltiummfav57447xts8mzfbtvgxb4ix4ctdwdnetljwjvuqzlfyn67t3+ fobsrjsfikbx5p/45b6pqamzsu7+ kvq5gy9wstxqlqf5jawvqkyunlxpojwl5qq8ij97eznyw2sp3dwkyiudo7wfudwlqhiwckdfbv80ezdwsvjygk+2t1rd3vyxxule8u+ qdvaff4t2paey5u00shff0j+ d6rpnncxxosx0fqbzzwvaafas9ou7eku3aifhem8bvjiagzdh2uxzboxrdsqab1tsv9aukmrt635jdshsbql92rr0vx3+ zajiawinaaabaaewbjewb96x1zmqkbmoagbwsy3pq/nmczs7l2vrwd3v5xaz1ubxx3nzcz/ iyl1tojverbf56ujy1on48dhve6y1qefbtxzfahflpk/o/ari/jcq3/uwsbsuny3ztmun+ Oyzfsipprcanotp9ualmjullb1ayg9lqzqfgwqua5fngzihjp2vdd95b+nfnnhyz+thtxmcm5evu7pes/xtgnwtzcys6xl2fl9veibBgtyfkxntnyvb2obhd42pgwfo3oe847swg6rlvjzn19cknqoqhppzqjezigviil4f1fr4nz20wzgvnwqemheva1njwvadfqi51p971uz4hjbhd54 =[[email protected]. ssh]# ^C[[email protected]. ssh]# pwd/root/. Ssh[[email protected]. ssh]#^c
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:
Xshell configuration key Public key and private key login