Centos8开启SSH服务


检测是否安装openssh-server

使用命令yum list installed | grep openssh-server
已安装会出现以下输出内容

[root@localhost /]# yum list installed | grep openssh-server
openssh-server.x86_64                8.0p1-4.el8_1                        @anaconda    
[root@localhost /]# 

没有安装使用安装命令yum install openssh-server

配置sshd文件

使用vim /etc/ssh/sshd_config命令打开配置文件,将第17,19,20行代码前的“#”去掉。

Port 22
#AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::

开启sshd服务

开启 sshd 服务,输入命令 sudo service sshd start

检测 sshd服务是否开启 ps -e | grep sshd

[root@localhost /]# ps -e | grep sshd
    916 ?        00:00:00 sshd
 116360 ?        00:00:00 sshd
 116409 ?        00:00:00 sshd

检测 22 号端口是否开启 netstat -an | grep 22

[root@localhost /]# netstat -an | grep 22
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0     64 192.168.138.134:22      192.168.138.1:8926      ESTABLISHED

将 sshd 服务设置为开机自启动systemctl enable sshd.service

检测是否开启systemctl list-unit-files | grep sshd

[root@localhost /]# systemctl list-unit-files | grep sshd
sshd-keygen@.service                       disabled 
sshd.service                               enabled  
sshd@.service                              static   
sshd.socket                                disabled 
sshd-keygen.target                         static  

查看服务器的IP地址

使用ifconfig查看IP地址

[root@localhost /]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.138.134  netmask 255.255.255.0  broadcast 192.168.138.255
        inet6 fe80::cc92:21a3:780f:aa72  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4e:7d:8b  txqueuelen 1000  (Ethernet)
        RX packets 258347  bytes 366454943 (349.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 36187  bytes 5297411 (5.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
# 其中“inet 192.168.138.134”就是你的本机地址

完成以上一系列的操作即可成功开启SSH服务,此时便可以使用Putty等工具远程管理你的服务器了。

声明:极客角度|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - Centos8开启SSH服务


拒绝拖延,勇于表达!