vim /etc/ssh/sshd_config

#允许密码认证
PasswordAuthentication no
ChallengeResponseAuthentication no
#秘钥认证
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
UsePAM yes
UseDNS no
AddressFamily inet
SyslogFacility AUTHPRIV
#允许root认证登录
PermitRootLogin yes
#SSHD 强制使用V2安全协议
Protocol 2
#设置SSH空闲超时退出时间
ClientAliveInterval 600  ClientAliveCountMax 2
#确保SSH LogLevel 设置为INFO
LogLevel INFO
#禁止SSH空密码用户登陆
PermitEmptyPasswords yes
#确保SSH MaxAuthTries 设置为3-6之间
MaxAuthTries 4

修改权限

chmod 700 ~/.ssh
chmod 644 ~/.ssh/authorized_keys

SSH 密码复杂度检查
文件位置
/etc/security/pwquality.conf
加固建议/etc/security/pwquality.conf, 把minlen(密码最小长度)设置为9-32,把minclass(至少包含小写字母,大写字母,数字,特殊字符等3类或者4类)
minlen=10 minclass=3

SSH 用户设置时间失效时间
文件位置
/etc/login.defs
加固建议 使用非密码登陆方式密钥对。请忽略此项, 在/etc/login.defs 中将PASS_MAX_DAYS 参数设置为60-180之间
PASS_MAX_DAYS 90 需同时执行命令设置root 密码失效时间 命令如下: chage --maxdays 90 root
设置密码修改最小间隔时间
PASS_MIN_DAYS 7 需同时执行命令设置root 密码失效时间 命令如下: chage --mindays 7 root

local-conf

Port 47121
AddressFamily inet
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
SyslogFacility AUTHPRIV
PermitRootLogin without-password
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
UsePAM yes
X11Forwarding yes
PrintMotd no
UseDNS 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
RSAAuthentication yes