Ssh logon provides two authentication methods: password authentication and key authentication. Password Authentication is one of the most common methods. Here we will introduce how to log on to linuxunix using the key authentication method.
Ssh logon provides two authentication methods: password authentication and key authentication. Password (password) authentication is one of the most common methods. Here we will introduce the key authentication method for logging on to linux/unix.
You can log on with the accesskey in three steps:
1. Generate a key (Public Key and private key );
2. Place the Public Key on the server ~ /. Ssh/authorized_key file;
3. Configure the ssh client to log on with the key.
1. Generate the Public key and Private Key)
Open Xshell, click "tools" in the menu bar, and select "User Key Generation Wizard..." in the pop-up menu, for example:
The "User Key Generation Wizard" dialog box is displayed. In the "Key Type" option, select the "RSA" public Key encryption algorithm, and the "Key Length" is set to "2048" Key Length, for example:
Click "Next" and wait for the key to be generated:
Next, enter the Name of the Key file in "Key Name". Here, it is "key". In "Passphrase", enter a password to encrypt the private Key, enter the password again for confirmation, such:
Click "Next", the key is generated (Public key Format select SSH2-OpenSSH Format), this shows the Public key, we can copy the Public key and then save, you can also directly Save the Public key to the file, for example. The private Key is not displayed here. You can export it to a file in "User Key Mangager:
Click the Save as file... button to Save the Public key to the disk. The file name is "key. pub.
2. Upload the Public Key to the server:
Log on to the server using Xshell, go to the "/root/. ssh/" directory, and run rzCommand(If there is no rzCommandRun yum install lrzsz), send key. pub to the server, and then run the following command to import the Public Key to the "authorized_keys" file:
- [Root @ localhost ~] # Cd/root/. ssh/
- [Root @ localhost. ssh] # rz
- Rz waiting to receive.
- [Root @ localhost. ssh] # cat me. pub> authorized_keys
- [Root @ localhost. ssh] # chmod 600 authorized_keys
- [Root @ localhost. ssh] # ls
- Authorized_keys known_hosts me. pub
- [Root @ localhost. ssh] # cat authorized_keys
- Ssh-rsa Secure/LZ00EZah8EjfZhqjAc/secure + secure/secure + Po4L1pbHLRf + TSoZ5RSBZZjY4/JMAzdXHNtnAyO0j0VNGbBXKUcNSAHZ
3. Configure Xshell to log on to the server using key authentication:
Open Xshell and click "New". The "New Session Properties" dialog box is displayed. In the "Connection" column, enter the IP address and port of the Public Key you Just configured, as shown in:
Click "Authentication" on the left to switch to the Authentication topic. Select "Public Key" for "Method" and enter "root" as the user name (the Public Key is stored in the root directory. in the ssh folder), select the generated private Key "key" in "User Key", and enter the encryption password of the private key in "Passphrase.
Click OK to complete ssh password-free logon configuration for Xshell.
Appendix: linux ssh-keygen command generation key:
In fact, ssh-keygen in linux can also generate a key, enter ssh-keygen-t rsa in linux, and enter the key name (key here) at the prompt) and the private key to encrypt the password. In the two files generated, "key" is the private key and "key. pub" is the public key. As shown in: