文件内容
[root@kylin-v10 sysctl.d]
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
SyslogFacility AUTH
PermitRootLogin yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
UsePAM yes
X11Forwarding no
PrintMotd no
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
Subsystem sftp /usr/libexec/openssh/sftp-server -l INFO -f AUTH
Protocol 2
LogLevel VERBOSE
PubkeyAuthentication yes
RSAAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
PermitUserEnvironment no
Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com
ClientAliveCountMax 0
Banner /etc/issue.net
MACs hmac-sha2-512,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha2-256-etm@openssh.com
StrictModes yes
AllowTcpForwarding no
AllowAgentForwarding no
GatewayPorts no
PermitTunnel no
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
HostbasedAcceptedKeytypes ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-512
GSSAPIKexAlgorithms gss-group14-sha256-,gss-group16-sha512-,gss-curve25519-sha256-
CASignatureAlgorithms ssh-ed25519,sk-ssh-ed25519@openssh.com,rsa-sha2-512,rsa-sha2-256
HostKeyAlgorithms ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-512
PubkeyAcceptedKeyTypes ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-512
内容解析
1. 基本配置
配置项 | 值 | 说明 |
---|
HostKey | /etc/ssh/ssh_host_rsa_key
/etc/ssh/ssh_host_ed25519_key | 指定SSH服务使用的密钥文件(RSA和Ed25519算法)。 |
SyslogFacility | AUTH | 日志通过syslog的AUTH 设施记录。 |
LogLevel | VERBOSE | 日志级别为详细模式(记录更多信息)。 |
Protocol | 2 | 仅允许SSH协议版本2(更安全)。 |
2. 认证与权限控制
配置项 | 值 | 说明 |
---|
PermitRootLogin | yes | 允许root用户登录(安全建议改为no 或prohibit-password )。 |
PasswordAuthentication | yes | 允许密码认证(安全建议改为no ,仅用密钥认证)。 |
PubkeyAuthentication | yes | 启用公钥认证。 |
RSAAuthentication | yes | 启用RSA密钥认证(旧版兼容,已逐渐被Ed25519替代)。 |
PermitEmptyPasswords | no | 禁止空密码登录。 |
PermitUserEnvironment | no | 禁止用户通过~/.ssh/environment 设置环境变量。 |
StrictModes | yes | 检查用户家目录和密钥文件的权限(防止权限不当泄露)。 |
3. 加密与算法配置
配置项 | 值 | 说明 |
---|
Ciphers | aes128-ctr,aes192-ctr,... | 允许的加密算法(禁用弱算法如CBC模式)。 |
MACs | hmac-sha2-512,... | 指定消息认证码算法(禁用MD5、SHA1等弱算法)。 |
KexAlgorithms | curve25519-sha256,... | 密钥交换算法(禁用Diffie-Hellman group1等旧算法)。 |
HostKeyAlgorithms | ssh-ed25519,... | 服务器主机密钥算法(禁用SSH-RSA)。 |
4. 功能限制
配置项 | 值 | 说明 |
---|
AllowTcpForwarding | no | 禁止端口转发(安全限制)。 |
AllowAgentForwarding | no | 禁止SSH代理转发。 |
GatewayPorts | no | 禁止远程主机连接本地转发端口。 |
PermitTunnel | no | 禁止创建隧道(如VPN)。 |
X11Forwarding | no | 禁用X11图形界面转发。 |
5. 其他配置
配置项 | 值 | 说明 |
---|
Banner | /etc/issue.net | 登录前显示自定义警告信息(通常放法律声明)。 |
UsePAM | yes | 启用PAM(Pluggable Authentication Modules)认证。 |
GSSAPIAuthentication | yes | 启用GSSAPI认证(用于Kerberos等企业环境)。 |
ClientAliveCountMax | 0 | 连接无响应时立即断开(防僵尸会话)。 |
安全建议
- 禁用密码登录(改为仅密钥认证):
PasswordAuthentication no
- 限制root登录:
PermitRootLogin no
- 更新算法:确保使用现代算法(如Ed25519、AES-GCM)。
- 重启SSH服务生效:
systemctl restart sshd
配置文件验证
检查语法是否正确:
sshd -t
若无输出则表示配置有效。