SSH (SecureShell) implements a remote login function similar to telnet. The difference is that it uses ciphertext to transmit data. In linux, SSH also supports client programs such as scp and sftp for remote host replication. SSH provides two authentication methods: 1. Password-based security authentication is similar to telnet, you can log on with the correct password. 2. Use the public key and private key pair for key-based security authentication. Password-based authentication ssh is very simple. By default, ssh is enabled in linux.
SSH (Secure Shell) implements a remote login function similar to telnet. The difference is that it uses ciphertext to transmit data. In linux, SSH also supports client programs such as scp and sftp for remote host replication. SSH provides two authentication methods.
1. Password-based security authentication
Similar to telnet, you can log on with the correct password.
2. Key-based security authentication
Use public key and private key pair for authentication
Password-based authentication
Password-based ssh is very simple. ssh is enabled by default in linux, so you only need to access ssh X. X.
RHEL-A access with RHEL-B
During the first ssh operation, a fingerprint string is obtained from the other party, which is the Public Key passed by the other party. Enter yes to accept the public key. The public key is saved in the. ssh folder under the root directory, and The. ssh directory is automatically created after the user logs in for the first time. Note: The ssh folder is hidden. You must use ls-a to view it.
650) this. width = 650; "border = 0>
In the. ssh folder, there is a file named known_hosts, which stores the RSA public key of the SSH server that the user has logged on.
650) this. width = 650; "border = 0>
Use ssh to access the target user. The current user is used by default.
Key-based authentication
General steps for setting key authentication:
1. Generate the user's public key and private key pair file on the SSH client
2. Add the SSH client's public key to the user's authentication file on the SSH server.
3. Verify Key Authentication
First, generate your public key and private key pair on the SSH client.
Ssh-keygen-t rsa
Passphrase is a string of passwords used to retrieve your private key after your private key is lost. Note that the password length cannot be too short; otherwise, the private key cannot be generated.
The ssh-keygen command will generate the public key and private key file in the. ssh directory.
650) this. width = 650; "border = 0>
Id_rsa is a private key file and the content must be kept strictly confidential.
Id_rsa pub is a public key file and can be published to an SSH server.
After the public key and private key are generated, You need to upload the public key to the SSH server. in the ssh directory, the public key name in the SSH server must be authorized_keys (to ensure that the other Party also has. ssh Directory, which can be logged on to the host or created directly. ssh folder ).
So how can we securely upload the public key to the SSH server? The solution is simple. You can successfully upload the file by using the SCP secure copy provided by SSH. :
650) this. width = 650; "border = 0>
When the SSH client has its own private key and the SSH server has a public key, you do not need to enter the user password after performing SSH, but you need to enter the passphrase password set earlier.
650) this. width = 650; "border = 0>
In this case, use the SFTP provided by SSH for access. You can also skip the password and log on directly. Note that, unlike vsftpd, SFTP does not use ports 21 and 20, so you do not need to enable the vsftpd service.
Other SSH Functions
SSH has a configuration file sshd_config, which is stored in the/etc/ssh directory. We know that SSH allows root users to log on by default, but root users can be disabled in this configuration file.
Vi/etc/ssh/sshd_config
Add PermitRootLogin no
Restart sshd service
Service sshd restart
SSH logon format
1. ssh username@X.X.X.X
2. ssh-l username X. X
Run the graphics program using SSH
Ssh-X username@X.X.X.X
SCP Function
SCP can be used to directly copy files between the SSH server and the client, similar to the CP command.
Copy files from the SSH server to the client
Scp root@192.168.20.1:/etc/passwd
Copy client files to the SSH server (~ Represents the root directory)
Scp XXX root@192.168.20.2 :~