Setting up SSH to login without password is simple and takes only two steps:
1. Create a public and private key locally:
Ssh-keygen -t RSA
2. Then upload the public key to the remote machine:
ssh-copy-ID -I. ~/. SSH 192.168.41.132
Under normal circumstances, the two-step setup can be no password login:
SSH 192.168. 41.132
But the problem is still to enter the password, online find information, have said to Restorecon , also said to chmod , finally found the problem in /var/log/audit/audit.log :
cat /var/log/audit/audit.log ... TYPE=AVC Msg=audit (1417198093.916:14807): avc:denied {search} for pid=1977 comm= "sshd" name= "/" DEV=VDB1 ino=2 S context=system_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:file_t:s0 tclass=dir ...
The error in avc:denied {search} is reported here, which is a selinux security issue, and the workaround is to:
1. Copy the error line from the /var/log/audit/audit.log file to the temporary file /tmp/error.txt :
grep " AVC: denied {search}" /var/log/audit/audit.log >/tmp/error.txt
2. Execute the following command to let the system find its own reasons:
# audit2why-i/tmp/error.txttype=avc msg=audit (1417198093.916:14807 for pid= 1977 comm="sshd" name="/" dev=vdb1 ino=2 scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:file_t:s0 tclass=dir was caused by:missing type Enforcement (TE) to allow rule. You can use the Audit2allow to generate a loadable module to the this access.
3, according to the above command output description, execution:
# audit2allow-i/tmp/error.txt-M local******************** IMPORTANT *********************** Make-I local.pp
4, according to the above command output description, execution:
Semodule-i local.pp
This resolves the avc:denied {search} problem.
After solving this problem, SSH login still needs to enter the password. For this, we also looked at the tail of the /var/log/audit/audit.log file, newly found avc:denied {getattr} error, the solution with the above 1-4 steps. After resolving these two errors, you can login without a password.
Troubleshooting SSH without password logon is unsuccessful