Linux ssh服务器配置

配置文件在/etc/sshd_config,注意只有root可rw,其他所有用户权限为---。

配置说明可参考man sshd_config。

如果更改了服务器端口号,并且启用了SELinux,需要执行以下命令:

semanage port -a -t ssh_port_t -p tcp YOUR_TCP_PORT

# 使用以下命令查看更改效果

# semanage port -l | grep "ssh"

# ssh_port_t tcp YOUR_NEW_PORT, 22

# 该更改复位后保持有效。

# 如需删除,将-a替换为-d即可:

# semanage port -d -t ssh_port_t -p tcp YOUR_TCP_PORT

# 使用semanage port -d -t ssh_port_t -p tcp 22无法删除port 22,

# 大意是说port 22由policy定义。待查。

建议更改默认端口。

另外几个建议更改的配置:

# The time after which the server disconnects if the user has not successfully logged in.

LoginGraceTime    30s

# Specifies the maximum number of authentication attempts permitted per connection.

# Once the number of failures reaches half this value, additional failures are logged. 

MaxAuthTries    4

# 限制root远程登录

PermitRootLogin no

原文地址:https://www.cnblogs.com/byeyear/p/9289063.html