아래 내용은 SELinux 관련 ssh 로그인 에러 해결책이며 ssh 를 비밀 번호 입력없이 사용하는 방법은 scp, ssh, rsync 를 key 비밀 번호/암호 입력창 없이 사용하기 를 참고하세요.


증상

remote ssh 서버에 공개키를 등록하고 .ssh 폴더와 authorized_keys 파일의 permission 도 맞는데 자동 로그인이 안 됨.


원인

사용자의 홈디렉토리나 .ssh 의 SELinux context 가 맞지 않으면 sshd가 authorized_keys 을 읽을 수 없어서 자동 로그인이 안 될수 있음


해결

  1. audit2why 로 SELinux audit 확인

    audit2why  < /var/log/audit/audit.log
    CODE
    type=AVC msg=audit(1389772205.869:373802): avc:  denied  { search } for  pid=31947 comm="sshd" name="/" dev=dm-2 ino=2 scontext=unconfined_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) allow rule.
                    You can use audit2allow to generate a loadable module to allow this access.
    CODE
  2. 로그인 못 하는 사용자 디렉토리의 context 확인

    ls -dlZ /home/lesstif/
    CODE
    drwxr-xr-x. lesstif rnd unconfined_u:object_r:file_t:s0  /home/lesstif/
    CODE

    /home/lesstif의 context 가 user_home_dir_t 여야 하는데 file_t 로 설정되어 있음

    ls -dlZ /home/lesstif/.ssh
    CODE
    drwx------. lesstif rnd unconfined_u:object_r:ssh_home_t:s0 /home/lesstif/.ssh/
    CODE

    .ssh context 는 정상적(ssh_home_t)으로 설정됨

  3. restorecon 으로 context 복구

    restorecon -R /home/lesstif
    CODE
  4. 다시 로그인 시도하여 확인