SSH 2FA는 루트 사용자 Centos 7을 제외한 모든 사람에게 작동합니다.

SSH 2FA는 루트 사용자 Centos 7을 제외한 모든 사람에게 작동합니다.

현재 특정 호스트에서 로그인할 때 비밀번호만 사용하고 2FA 인증 없이 루트 사용자 로그인을 구현하려고 합니다. 지금까지 내 sshd_config는 다음과 같습니다.

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#Authentication
AllowUsers myuser
ChallengeResponseAuthentication yes
AuthenticationMethods keyboard-interactive
#PermitRootLogin no
PasswordAuthentication no
PermitEmptyPasswords no
UsePAM yes
MaxAuthTries 3


KexAlgorithms [email protected],ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256
Ciphers [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr
MACs [email protected],[email protected],[email protected],hmac-sha2-512,hmac-sha2-256,[email protected]


LogLevel VERBOSE


UseDNS yes
IgnoreRhosts yes
HostbasedAuthentication no
X11Forwarding no
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL
#Banner /etc/ssh/banner

#SFTP
#Subsystem sftp  /usr/lib/ssh/sftp-server -f AUTHPRIV -l INFO

Match Address 100.100.100.100
  PermitRootLogin yes

그러나 이것은 작동하지 않고 계속해서 비밀번호를 묻는 메시지를 표시합니다. 그래서 약간의 조사 끝에 /etc/pam.d/sshd를 조정했습니다(noauth 그룹을 만들고 여기에 루트 사용자를 추가했습니다).

#%PAM-1.0
auth       required     pam_sepermit.so
auth       substack     password-auth
auth       include      postlogin
# Used with polkit to reauthorize users in remote sessions
-auth      optional     pam_reauthorize.so prepare
account    required     pam_nologin.so
account    include      password-auth
password   include      password-auth
# pam_selinux.so close should be the first session rule
session    required     pam_selinux.so close
session    required     pam_loginuid.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session    required     pam_selinux.so open env_params
session    required     pam_namespace.so
session    optional     pam_keyinit.so force revoke
session    include      password-auth
session    include      postlogin
# Used with polkit to reauthorize users in remote sessions
-session   optional     pam_reauthorize.so prepare
auth [success=done default=ignore] pam_succeed_if.so user ingroup noauth
auth required pam_google_authenticator.so echo_verification_code

하지만 불행하게도 아무것도 바뀌지 않았고 여전히 루트로 로그인할 수 없습니다. 다른 모든 사람은 2FA 인증을 사용해야 하기 때문에 Google pam 모듈에 nullok를 추가할 수 없습니다.

도움을 주셔서 감사합니다 :)

답변1

나는 내 문제를 (일종의) 해결했습니다. pam 모듈에 nullok를 추가하고 /etc/profile에 짧은 스크립트를 추가하여 모든 사용자가 2FA(루트 제외)를 설정하도록 강제합니다(루트 제외). . 누구든지 관심이 있다면 스크립트는 다음과 같습니다.

if [ ! -f "$HOME"/.google_authenticator ]; then
    if [ ! "$USER" = "root" ]; then
        google-authenticator -t -d -f -r 3 -R 30 -W
        echo "Please scan the above QR-Code with your 2FA App, or copy the given link. Otherwise, you can no longer log in via SSH"
    fi
fi

관련 정보