linux-ssh优化

发布时间 2023-06-12 10:51:11作者: 安生丶
1.修改ssh端口
vim /etc/ssh/sshd_config
#Port 22
Port 20199  #指定端口
Port 20100
#ListenAddress 0.0.0.0
#ListenAddress ::

2.添加ssh白名单
[root@small ~]# vim /etc/hosts.allow
sshd:10.10.10.
sshd:10.241.107.85:allow
sshd:10.28.234.124:allow
sshd:172.16.2.30:allow  


3. 设置禁止root用户远程登录
解决办法:需要修改 /etc/ssh/sshd_config 配置,允许登录

1.编辑配置文件
   命令:vi /etc/ssh/sshd_config
2.文件中找到PermitRootLogin
  #PermitRootLogin without-password
  将#去掉,without-password改为yes
  PermitRootLogin yes
3.退出并保存,重启ssh
  命令:service sshd restart


4. ssh连接失败
[root@ZJHZ-SERVICE-A1 mone]# ssh ecs-user@10.25.71.28 -p 20199
ssh_exchange_identification: read: Connection reset by peer
解决:
vi /etc/hosts.allow
追加:
sshd: ALL
重启ssh就ok了
service sshd restart