SSH key-based logon and password-disabled logon practices
Preface
Whether it's a personal VPS or a server that enterprises allow access to the public network, if the SSH password authentication method for port 22 is enabled, it may also happen frequently when it is cracked by many hackers. Enterprises can use firewalls for restrictions. Common users may also use ports 22, weak passwords, and other protection methods, however, the current relatively safe and simple solution is to enable SSH to log on with a key and disable Password Logon.
This is the most secure login management method.
Generate PublicKey
We recommend that you set and keep in mind the passphrase phrase. Take Linux as an example.
Linux: ssh-keygen-t rsa
[Private key (id_rsa) and Public Key (id_Rsa. pub)]
Windows: SecurCRT/Xshell/PuTTY
[SSH-2 RSA 2048]
# Generate an SSH key pair
ssh-keygen -t rsa
Generatingpublic/private rsa key pair.
# We recommend that you press enter to use the default path.
Enter file in which to save the key (/root/.ssh/id_rsa):
# Enter the password phrase (if left blank, press Enter)
Enter passphrase (empty forno passphrase):
# Repeated password phrase
Enter same passphrase again:
Your identification has been saved in/root/.ssh/id_rsa.
Yourpublic key has been saved in/root/.ssh/id_rsa.pub.
The key fingerprint is:
aa:8b:61:13:38:ad:b5:49:ca:51:45:b9:77:e1:97:e1 root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
| .o. |
| .. . . |
| . . . o o |
| o. . . o E |
|o.= . S . |
|.*.+ . |
|o.* . |
| . + . |
| . o. |
+-----------------+
Copy key pair
You can also manually create a directory and authorized_keys on the client.
# Copy the public key to the server without a password. If port 22 is changed, run the following command:
#ssh-copy-id -i ~/.ssh/id_rsa.pub "-p 10022 user@server"
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.15.241
Modify the SSH configuration file
# Edit the sshd_config file
vi /etc/ssh/sshd_config
# Disable password verification
PasswordAuthenticationno
# Enable key verification
RSAAuthentication yes
PubkeyAuthentication yes
# Specify the public key database file
AuthorsizedKeysFile.ssh/authorized_keys
We recommend that you keep one more session before restarting the SSH service.
# RHEL/CentOS System
service sshd restart
# Ubuntu System
service ssh restart
# Debian system
/etc/init.d/ssh restart
Manually add management users
You can add the user annotation mark after = to facilitate management.
echo 'ssh-rsa XXXX'>>/root/.ssh/authorized_keys
# Review
cat /root/.ssh/authorized_keys
SSH service remote access to Linux Server login is slow
How to Improve the SSH login authentication speed of Ubuntu
Enable the SSH service to allow Android phones to remotely access Ubuntu 14.04
How to add dual authentication for SSH in Linux
Configure the SFTP environment for non-SSH users in Linux
Configure and manage the SSH service on Linux
Basic SSH tutorial
SSH password-free logon details
This article permanently updates the link address: