Linux学习填坑 修改ssh默认端口及禁用root账户

1、修改ssh默认端口

1.1、修改ssh配置文件

打开 /etc/ssh/sshd_config 配置文件,没修改之前如下:

#       $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy 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 ::

删除#Port 22前面的#,在下一行添加一个新的端口号如:Port 10086 (最好大于10000 不能超过65535),防止修改端口失败无法登陆

Port 22
Port 10086

保存退出

1.2、重启ssh服务

# service sshd restart

1.3、测试修改端口ssh连接

用新添加的端口号进行测试连接

1.4、禁用22端口

        修改 /etc/ssh/sshd_config 配置文件,去掉Port 22,重启SSH服务


2、禁用root账户登录

2.1、添加用户

root添加一个名为 test 的用户:

# useradd test

为该用户设置密码:

# passwd test

然后需要输入两次密码:

Changing password for user test.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

2.2、修改ssh配置文件

        打开 /etc/ssh/sshd_config 文件,定位到此行:

#PermitRootLogin yes

去掉前面的#号,并将'yes'改为'no',保存退出

2.3、重启ssh服务

# service sshd restart

2.4、使用新用户登录

更改ssh连接属性,使用新添加的用户名及密码,以普通用户连接

2.5、使用root权限

        若某些操作权限不足,需要使用root权限可用以下命令:

# su root


猜你喜欢

转载自blog.csdn.net/Derek_Yam/article/details/80431433
今日推荐