web-dev-qa-db-ja.com

SSH-ローカルネットワークの外部からのgoogle-authenticatorのみが必要です

Debianバリアント(osmc)の実行

私がやろうとしていること:

  • キーとGoogle認証システムの両方を必要とするパスワードによるsshを無効にします。それはすべて機能しています
  • しかし今、私は外部ローカルネットワークからの2要素認証のみを要求しようとしています(バックアップスクリプトの方が簡単ですが、これを行う別のより良い方法がある場合は、言ってください)

現在、関連する場合に備えて、WindowsボックスからPuTTYとページェントを使用してテストしています

だから私はここでソリューションを使用しています--- https://serverfault.com/questions/799657/ssh-google-authenticator-ignore-whitelist-ips

現在の状況-ネットワークの外部から接続する場合でも、必要に応じて2要素認証が必要です。ネットワークの内部からは、キーを認識しているように見えますが、「さらに認証が必要です」というエラーが表示されます。

助けてくれてありがとう

Sudo systemctl status ssh

Aug 25 19:51:36 mosmc sshd[10528]: error: PAM: Permission denied for osmc from beast
Aug 25 19:51:36 mosmc sshd[10528]: Failed keyboard-interactive/pam for osmc from 192.168.21.3 port 54330 ssh2
Aug 25 19:51:36 mosmc sshd[10528]: error: Received disconnect from 192.168.21.3: 14: No supported authentication methods available [preauth]

以下のファイルの猫(私の混乱がそれを壊し続けているので、私がちょうどこのメディアボックスのインストールをスクリプト化したスクリプトについて言及しているところ)

    osmc@mosmc:~$ cat /etc/ssh/sshd_config
# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port XXXXXXX #changed by sshinstall
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2

# Inserted hostkeys by ssh-install script
HostKey /etc/ssh/ssh_Host_ed25519_key
HostKey /etc/ssh/ssh_Host_rsa_key
HostKey /etc/ssh/ssh_Host_ecdsa_key
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]
#End of inserted code
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024

# Logging
SyslogFacility AUTH
LogLevel VERBOSE #edited by script

# Inserted ftp by ssh-install script
# Log sftp level file access (read/write/etc.) that would not be easily logged otherwise.
Subsystem internal-sftp  /usr/lib/ssh/sftp-server -f AUTHPRIV -l INFO
#End of inserted code

# Authentication:
LoginGraceTime 120
PermitRootLogin no #edited by script
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile     %h/.ssh/authorized_keys

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

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication yes #edited by script

# Change to no to disable tunnelled clear text passwords
PasswordAuthentication no #edited by script

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

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*


# 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'.

# Inserted google-auth settings by ssh-install script
AuthenticationMethods publickey,keyboard-interactive:pam
KbdInteractiveAuthentication yes
# Ensure /bin/login is not used so that it cannot bypass PAM settings for sshd.
UseLogin no
#End of inserted code
UsePAM yes

access-local.conf

osmc@mosmc:~$ cat /etc/security/access-local.conf
# only allow from local IP range
+ : ALL : 192.168.21.0/24
+ : ALL : LOCAL
- : ALL : ALL

pam.d

osmc@mosmc:~$ cat /etc/pam.d/sshd
# PAM configuration for the Secure Shell service

# Inserted PAM settings by ssh-install script
auth [success=1 default=ignore] pam_access.so accessfile=/etc/security/access-local.conf
auth required pam_google_authenticator.so
#End of inserted code

# Standard Un*x authentication.
#@include common-auth #commented out  by sshinstall

# Disallow non-root logins when /etc/nologin exists.
account    required     pam_nologin.so

# Uncomment and edit /etc/security/access.conf if you need to set complex
# access limits that are hard to express in sshd_config.
# account  required     pam_access.so

# Standard Un*x authorization.
@include common-account

# SELinux needs to be the first session rule.  This ensures that any
# lingering context has been cleared.  Without this it is possible that a
# module could execute code in the wrong domain.
session [success=ok ignore=ignore module_unknown=ignore default=bad]        pam_selinux.so close

# Set the loginuid process attribute.
session    required     pam_loginuid.so

# Create a new session keyring.
session    optional     pam_keyinit.so force revoke

# Standard Un*x session setup and teardown.
@include common-session

# Print the message of the day upon successful login.
# This includes a dynamically generated part from /run/motd.dynamic
# and a static (admin-editable) part from /etc/motd.
session    optional     pam_motd.so  motd=/run/motd.dynamic
session    optional     pam_motd.so noupdate

# Print the status of the user's mailbox upon successful login.
session    optional     pam_mail.so standard noenv # [1]

# Set up user limits from /etc/security/limits.conf.
session    required     pam_limits.so

# Read environment variables from /etc/environment and
# /etc/security/pam_env.conf.
session    required     pam_env.so # [1]
# In Debian 4.0 (etch), locale-related environment variables were moved to
# /etc/default/locale, so read that as well.
session    required     pam_env.so user_readenv=1 envfile=/etc/default/locale

# SELinux needs to intervene at login time to ensure that the process starts
# in the proper default security context.  Only sessions which are intended
# to run in the user's context should be run after this.
session [success=ok ignore=ignore module_unknown=ignore default=bad]        pam_selinux.so open

# Standard Un*x password updating.
@include common-password
3
beardedfool
auth [success=done default=ignore] pam_access.so accessfile=/etc/security/access-local.conf

答えのようです。詳細を確認しながら編集する。

から http://linux-pam.org/Linux-PAM-html/sag-configuration-file.html

成功=完了

モジュールスタックを終了し、PAMがすぐにアプリケーションに戻るという副作用があるokと同等です。

デフォルト=無視

モジュールのスタックで使用する場合は無視してください。モジュールの戻りステータスは、アプリケーションが取得する戻りコードには影響しません。

から- https://serverfault.com/questions/134471/success-n-control-syntax-in-pam-conf-pam-d-files#134488

success = 1は行をスキップします。

他の誰かが何が起こっているのかを説明するより良い答えを書きたいのなら、私はそれを喜んで受け入れます。

私を正しい部分に向けてくれたHostfissionに感謝します。

2
beardedfool

@beaderdfool、ハードワークに感謝します。私はあなたの答えがうまくいったことを確認するために安心していますが、私は任意のパスワードで認証できましたでした。私は少し遊んで、次のハッキーな解決策を思いついた:

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

最初の行はaccess.confのルールを使用しています。それが一致する場合、success=1は次の行をスキップします。言い換えると、ローカルネットワークでの一致は、Google認証システムをスキップし、次にpam_unix.soからのrequiredパスワードの一致を試行します。

一方、pam.access.soが一致しない場合、google_authenticatorが実行され、合格した場合はsufficientになります。つまり、スタック内の他の何も気にしない、つまりpam_unix.soそして追加のパスワードは必要ありません。

したがって、私の設定は次のとおりです。

  • ローカルネットワークには、ユーザー名とパスワードのみが必要です。
  • 他のすべてには、秘密鍵(/ etc/sshd_configで設定)とGoogle認証システムが必要です

私はコメントを残したでしょうが、十分な信用はありませんでした。

0
jdinsd