Ssh

OpenSSH 守護程序忽略 ServerKeyBits 指令

  • March 1, 2019

我的 Fedora 19 x86_64 虛擬機出現問題。

它似乎忽略了我的 4096 位密鑰設置。我已將ServerKeyBits指令設置為4096,停止 sshd 服務,刪除/etc/ssh/目錄中的所有主機密鑰,然後重新啟動 sshd 服務。它會創建 2048 位的新密鑰。我知道這一點,因為當我這樣做時,它會在另一台機器上ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pub返回,而我已經為它返回了。2048``4096

為什麼我的 OpenSSH 服務忽略了它的ServerKeyBits指令?它似乎沒有忽略其他指令,例如關閉密碼身份​​驗證並只允許密鑰對身份驗證。

我已經安裝了openssh-6.2p2-7.fc19.x86_64openssl-1:1.0.1e-37.fc19.1.x86_64

提前致謝。

我的配置文件如下:

#       $OpenBSD: sshd_config,v 1.89 2013/02/06 00:20:42 dtucker Exp $

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

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

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

# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
Port 22
AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::

# The default requires explicit activation of protocol 1
Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 1h
ServerKeyBits 4096

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

RSAAuthentication yes
PubkeyAuthentication yes

# 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
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and 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
PasswordAuthentication no
PermitEmptyPasswords no

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

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

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

# 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'.
# WARNING: 'UsePAM no' is not supported in Fedora and may cause several
# problems.
#UsePAM no
UsePAM yes

#AllowAgentForwarding yes
AllowTcpForwarding no
#GatewayPorts no
#X11Forwarding no
X11Forwarding no
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
UsePrivilegeSeparation sandbox          # Default for new installations.
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none
Banner /etc/issue.net

# Accept locale-related environment variables
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 LANGUAGE
AcceptEnv XMODIFIERS

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

# Uncomment this if you want to use .local domain
#Host *.local
#       CheckHostIP no

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

用於的密鑰ServerKeyBits是臨時密鑰。不是生成的主機密鑰。它也適用於協議的版本 1,基本上不再相關,並且您在 Protocol 2粘貼的配置文件中禁用了它。因此,在您的配置上下文中,更改 ServerKeyBits 完全沒有意義。

伺服器密鑰位

定義臨時協議版本 1 伺服器密鑰中的位數。最小值為 512,預設值為 1024。

如果要創建 4096 位 rsa 主機密鑰,請發出這樣的命令。

ssh-keygen -q -f /etc/ssh/ssh_host_rsa_key -N '' \
          -b 4096 -t rsa

DSA 密鑰固定為 1024 位,而 ecdsa 密鑰可以是 256、384 或 521 位。所以這將生成具有最多位數的 ecdsa 密鑰。

ssh-keygen -q -f /etc/ssh/ssh_host_ecdsa_key -N '' \
          -b 521 -t ecdsa

我不確定 Centos/Redhat/Fedora,但在基於 Debian 的發行版上,主機密鑰是作為 postinst 腳本的一部分生成的。在某個時間點,如果這些鍵失去,init.d 腳本也會重新創建它們。如果您應該查看 Fedora 上的 ssh 啟動腳本而不是 sshd_config,我不會感到驚訝。

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