OpenSSH 守护进程忽略 ServerKeyBits 指令

OpenSSH 守护进程忽略 ServerKeyBits 指令

我的 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_64安装好了openssl-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

答案1

该密钥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,我并不感到惊讶。

相关内容