1. Centos7开启SSH服务
1.1. 1. 安装openssh-server
首先检查是否已经安装了openssh-server
, 在终端输入:
$ yum list installed | grep openssh-server
如果已经安装了sshd
,则会输出结果:
openssh-server.x86_64 7.4p1-16.el7 @anaconda
如果未显示上面结果,则手动安装openssh-server
,在终端如下命令进行安装
$ yum install -y openssh-server
1.2. 2. 修改配置信息
使用vim编辑器打开配置文件sshd_config
$ vim /etc/ssh/sshd_config
修改如下配置
Port 22 #端口号22
ListenAddress 0.0.0.0 #监听任意IPv4接入
ListenAddress :: #监听任意IPv6接入
PermitRootLogin yes #开启远程接入
PasswordAuthentication yes #开启密码认证
1.3. 3. 设置开机启动并启动ssh服务
使用systemctl
设置sshd
服务开机启动:
$ systemctl enable sshd #设置开机启动sshd服务
$ systemctl start sshd # 启动sshd服务
使用netstat
命令检测是否监听22端口:
$ netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 377/sshd
tcp6 0 0 :::22 :::* LISTEN 377/sshd
使用ps
查看sshd
进程是否运行:
$ ps -ef | grep sshd
root 377 1 0 09:12 ? 00:00:00 /usr/sbin/sshd -D