SSH(Secure SHell)
SSH的英文全称是Secure SHell。通过使用SSH,你可以把所有传输的数据进行加密,这样“中间人”这种攻击方式就不可能实现了,而且也能够防止DNS和IP欺骗。还有一个额外的好处就是传输的数据是经过压缩的,所以可以加快传输的速度。SSH有很多功能,它既可以代替telnet,又可以为ftp、pop、甚至ppp提供一个安全的“通道”。
SSH在Linux中的服务是sshd,安装openssh后才可开启。CentOS 7 安装后默认情况下是不启动sshd服务,即无法通过ssh服务远程连接。
首先查看系统是否安装openssh,一般情况想都是默认安装了。
1 | [root@localhost ~]# rpm -qa | grep ssh |
如果没有安装可以通过yum在线安装。
1 | yum install openssh |
手动设置启动ssh服务
简单的设置就是在命令行中启动sshd服务。这样做比较快捷直接,但是只能对当前状态有效,一旦重启系统就丢失了该服务。
1 | [root@localhost ~]# systemctl start sshd |
设置自动启动ssh服务
1、systemclt设置自动启动
通过systemctl命令可以将sshd服务加到开机自启动列表里。实现开机自动启动sshd服务。
1 | systemctl enable sshd |
2、修改ssh监听端口
在sshd_config
文件中存放了端口、控制策略等信息。
1 | vi /etc/ssh/sshd_config |
结果如下
1 | # $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $ |
3、需要修改的地方
- 首先修改端口,端口设置为自定义端口,即1024之后的端口,这里设置为8090。
1 | port 8090 |
- 禁止空密码用户登录。
1 | PermitEmptyPasswords no |
- 开启密码登录授权(默认即开启)
1 | PasswordAuthentication yes |
- 禁止root账户使用ssh登录,这种设置通常用于互联网服务器,防止提权后用root账户登录搞破坏。
1 | PermitRootLogin no |
4、注意其中关于port的提示文字
1 | # If you want to change the port on a SELinux system, you have to tell |
修改端口的时候需要添加到防火墙的控制中,否则无法使用ssh连接。
1 | [root@localhost ~]# semanage port -l | grep ssh #查看当前ssh服务监听的端口 |
semanage只是端口工具,修改防火墙只能使用firewall-cmd
1 | [root@localhost ssh]# yum provides firewall-cmd #查找防火墙工具所在的包 |