Background
A complex password is required for each login, and no one is trying to log in to the root account. Feel flustered, so you have to set a more secure way to log in.
Configuring SSH password-free login takes 4 steps
- Preparatory work
- Generate public and private keys
- Import public key to authentication file, change permissions
- Test
1. Preparatory work
Confirm the configuration file for native sshd (requires root access)
vi /etc/ssh
1) Modify the following content
Rsaauthentication Yes #设置开启使用RSA算法的基于rhosts的安全验证;RSAAuthentication没有则自行添加。
Pubkeyauthentication yes# Set the public key authentication to open;
Authorizedkeysfile. ssh/authorized_keys# behind the directory, is the public key that you upload to save the file;
Strictmodes no# means to set off SSH to check the permissions and ownership of the user home directory and rhosts file before receiving the login request.
Passwordauthentication no# prohibit login with password authentication
2) Don't worry about starting the SSHD service first
Pilot the key you need to restart the service, or you know the remote do not want to log on.
2. Generate public and private keys
There are three ways to generate a public key:
1) Use the command
cd/root/. SSH Ssh-keygen -t RSA
I haven't tested this.
2) Use SECURECRT to generate the key and upload
Tool tools-Create Public key
Keytype:rsa
Sets the password for the public key that is used at a later logon. You can also not enter a password
Set the public key length: This is the default 2048.
Set the file name of the public key, Id_rsa set here
The following two files are generated when the. pub suffix is the public key, no suffix files when the private key is used (XFTP)
3. Import the public key to the server and change the permissions
1) We copy a public key file [id_rsa.pub] named [Authorized_keys].
2) upload [Authorized_keys] with xftp etc to/root/.ssh/to overwrite the original file.
3) Change file permissions on the server
chmod /root/. SSH chmod /root/. ssh/authorized_keys
4) Restart the SSH service
#CentOS versions prior to 7 do: service sshd Restart#centos 7 please perform: systemctl restart Sshd.service
4. Test using SECURECRT Login
Secure into the Admin key menu, add the previously created private key file, and enter the password.
Try to log in and log on successfully.
If you can not log in successfully, it must be the disaster of SELinux.
PS for this I got a long time, the entry is difficult!
We can try to close SELinux
Temporarily off (resume after reboot):
0
Permanent shutdown (requires restart):
vi /etc/selinux/config selinux=disabled
Linux setup SSH login (SECURECRT)