Linux

正確配置 SSHD 配置文件?

  • December 9, 2019

我在我的 linux 機器上使用 ssh,我想確保它盡可能防水,只允許通過ed25519橢圓曲線加密 sigs 進行 ssh。

我以為我設置正確,禁用密碼,沒有 PAM 等。

它似乎工作正常,但今天我注意到我沒有authorised_keys指定文件,並且我已經PubkeyAuthentication註釋掉了。

當密碼身份驗證設置為否時,這些內容是否隱式設置為是?

這個設置好嗎?

#       $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

#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 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2

#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 no
#PermitEmptyPasswords no

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

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

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing

我不確定是否排除所有公鑰算法,除了ed25519不是過分熱心,它是一個很好的安全策略。Security StackExchange當然可以告訴你更多關於這個主題的資訊。

SSH預設值在sshd_config 手冊頁中列出,但最好閱讀系統上的那個:例如 Debian 更改了一些上游預設值。PubkeyAuthentication’ 的預設值是yes並且AuthorizedKeysFile’ 的預設值是~/.ssh/authorized_keys(美式拼寫)。

假設您想要:禁用所有基於密碼的身份驗證並僅使用ed25519公鑰加密,考慮到您只需要的上游預設值:

ChallengeResponseAuthentication no
#GSSAPIAuthentication no by default
#HostbasedAuthentication no by default
#KbdInteractiveAuthentication defaults to ChallengeResponseAuthentication
#KerberosAuthentication no by default
PasswordAuthentication no
#PubkeyAuthentication yes by default
PubkeyAcceptedKeyTypes ssh-ed25519
UsePAM yes

整體禁用PAM會禁用****帳戶會話PAM 模組,從而為使用者提供更好的環境。無論如何都不會使用 auth PAM 模組,因為密碼和質詢-響應身份驗證都被禁用**。**

引用自:https://serverfault.com/questions/994894