동일한 로컬 네트워크에서 SSH 2단계 인증 우회 지원

동일한 로컬 네트워크에서 SSH 2단계 인증 우회 지원

몇 가지 다른 애플리케이션을 사용해야 하기 때문에 동일한 네트워크에서 SSH 연결이 이루어질 때 Google의 2단계 인증 pam.d 모듈을 우회할 수 있어야 합니다. 온라인에는 이에 대한 정보가 거의 없지만 스택 네트워크에 대한 몇 가지 질문이 있지만 어떤 솔루션도 나에게 도움이 되지 않았습니다. 이러한 솔루션이 Linux에만 국한된 것인지, 아니면 제가 뭔가를 놓치고 있는 것인지 잘 모르겠습니다. 여기서는 모든 경우에 macOS를 사용하고 있습니다.

나는 이러한 설정에 익숙하지 않습니다. 동일한 로컬 네트워크에 있지 않으면 비밀번호, 키, 2FA가 필요하지만 동일한 로컬 네트워크에 있으면 2FA를 건너뜁니다.

현재 설정:

SSH에는 유효한 키, 비밀번호 및 2단계 인증이 필요합니다.

문서 내용:

/etc/pam.d/sshd

auth       optional       pam_krb5.so use_kcminit
auth       optional       pam_ntlm.so try_first_pass
auth       optional       pam_mount.so try_first_pass
auth       required       pam_opendirectory.so try_first_pass
auth       required       pam_google_authenticator.so nullok
account    required       pam_nologin.so
account    required       pam_sacl.so sacl_service=ssh
account    required       pam_opendirectory.so
password   required       pam_opendirectory.so
session    required       pam_launchd.so
session    optional       pam_mount.so

/etc/ssh/ssh_config

# Host *
#   ForwardAgent no
#   ForwardX11 no
#   PasswordAuthentication yes
#   HostbasedAuthentication no
    GSSAPIAuthentication yes
    GSSAPIDelegateCredentials no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   IdentityFile ~/.ssh/id_ecdsa
#   IdentityFile ~/.ssh/id_ed25519
#   Port 22
#   Protocol 2
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
#   MACs hmac-md5,hmac-sha1,[email protected]
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
#   ProxyCommand ssh -q -W %h:%p gateway.example.com
#   RekeyLimit 1G 1h

Host *
    SendEnv LANG LC_*

/etc/ssh/sshd_config

#Protocol Version
Protocol 2

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

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
MaxAuthTries 3
#MaxSessions 10

PubkeyAuthentication yes
AuthenticationMethods publickey,keyboard-interactive:pam

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile  .ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
PermitEmptyPasswords no

# Change to no to disable s/key passwords
ChallengeResponseAuthentication yes

# Kerberos options
KerberosAuthentication yes
KerberosOrLocalPasswd yes
KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
ClientAliveInterval 360
ClientAliveCountMax 0
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# pass locale information
AcceptEnv LANG LC_*

# no default banner path
Banner /etc/ssh/banner

# override default of no subsystems
Subsystem   sftp    /usr/libexec/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#   X11Forwarding no
#   AllowTcpForwarding no
#   PermitTTY no
#   ForceCommand cvs server

편집하다:

아래 나열된 링크의 스택 게시물에 나열된 솔루션의 몇 가지 다른 조합을 시도했지만 제공된 솔루션이 작동하지 못했습니다. 내 구성에 뭔가 빠졌는지, macOS를 사용하는 것과 관련된 것인지, pam.d의 sshd 파일에 나열된 순서가 잘못된 것인지 알 수 없습니다.

SSH - 로컬 네트워크 외부의 google-authenticator만 필요합니다.

https://serverfault.com/questions/799657/ssh-google-authenticator-ignore-whitelist-ips

나는 이것을 pam.d의 sshd 파일에 추가하려고 시도했습니다.

auth [success=1 default=ignore] pam_access.so accessfile=/etc/security/access.conf
auth sufficient pam_google_authenticator.so

그리고 access.conf 파일을 /etc/security/access.conf에 추가하십시오.

+ : ALL : 10.0.1.0/24
+ : ALL : LOCAL
+ : ALL : 10.0.1.4
+ : ALL : 10.0.1.6
+ : ALL : 10.0.1.16
+ : ALL : 10.0.1.20
- : ALL : ALL

답변1

나는 이것을 Mac에서 사용합니다:

/etc/pam.d/sshd

# sshd: auth account password session
auth       binding        /usr/local/opt/google-authenticator-libpam/lib/security/pam_google_authenticator.so
auth       optional       pam_krb5.so use_kcminit
auth       optional       pam_ntlm.so try_first_pass
auth       optional       pam_mount.so try_first_pass
auth       required       pam_opendirectory.so try_first_pass
account    required       pam_nologin.so
account    required       pam_sacl.so sacl_service=ssh
account    required       pam_opendirectory.so
password   required       pam_opendirectory.so
session    required       pam_launchd.so
session    optional       pam_mount.so

/etc/ssh/sshd_config

LogLevel VERBOSE
PermitRootLogin no
PubkeyAuthentication yes
AuthorizedKeysFile  .ssh/authorized_keys
PasswordAuthentication no
PermitEmptyPasswords no
AuthenticationMethods publickey,keyboard-interactive:pam
ChallengeResponseAuthentication yes
UsePAM yes
AcceptEnv LANG LC_*
Subsystem   sftp    /usr/libexec/sftp-server
Match Address fc00::/7,10.0.1.0/24
    PasswordAuthentication no
    AuthenticationMethods publickey

이렇게 하면 로컬 네트워크 외부의 연결만 2FA를 제공해야 하며 로컬 연결은 Pubkey에만 기반을 둡니다.

답변2

"로컬 네트워크 외부에서 연결할 때만 OTP 요청" 섹션을 참조하세요.아치스 위키:

이를 달성하려면 파일(예: /etc/security/access-local.conf)을 생성하고 2FA를 우회할 수 있는 네트워크를 추가하세요.

# only allow from local IP range
+ : ALL : 192.168.20.0/24
# Additional network: VPN tunnel ip range (in case you have one)
+ : ALL : 10.8.0.0/24
+ : ALL : LOCAL
- : ALL : ALL

그런 다음 /etc/pam.d/sshd를 편집하고 다음 줄을 추가합니다.

#%PAM-1.0
#auth     required  pam_securetty.so     #disable remote root
auth [success=1 default=ignore] pam_access.so accessfile=/etc/security/access-local.conf
auth      required  pam_google_authenticator.so
auth      include   system-remote-login
account   include   system-remote-login
password  include   system-remote-login
session   include   system-remote-login

위키에서와 동일한 설정을 사용하고 있다고 생각했지만 작동 시스템의 구성은 다음과 같습니다.

#%PAM-1.0
auth [success=done default=ignore] pam_access.so accessfile=/etc/security/otp-access.conf
auth [success=done new_authtok_reqd=done default=die] pam_google_authenticator.so nullok

업데이트 - 여전히 작동하지 않으므로 처음으로만 사용하세요.

auth [success=done new_authtok_reqd=done default=die] pam_google_authenticator.so nullok

그런 다음 2f 인증이 유효한지 확인하십시오. SSH 키와 2f 코드만 사용해야 합니다. 비밀번호를 요구해서는 안 됩니다.

success=done부분은 2f가 완료되면 auth pam 스택을 종료하므로 아래 인증 라인이 처리되지 않음을 의미합니다.

작동하면 첫 번째 행을 삽입하십시오.

auth [success=done default=ignore] pam_access.so accessfile=/etc/security/otp-access.conf

즉, IP가 정확하면 auth pam 스택 처리가 다시 중지됩니다(2f를 사용하여 두 번째 줄로 이동하지 않음).

관련 정보