开发随笔

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

centos7远程连接(开启SSH)

centos7 64位操作系统

一.先查看网络是否连接,使用ping www.baidu.con ,试试是否能ping通网站,可以代表网络已经连接。

[root@localhost home]# ping www.baidu.com
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=128 time=40.1 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=128 time=96.2 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=128 time=43.5 ms

ping通了,说明网络连接没有问题。

二.可以先输入命令netstat -an| grep ssh,查看ssh是否开启,如果开启就可以直接远程连接.

[root@localhost home]# netstat -an |grep ssh
.......................
........................

显示没有开启

三.开启SSH连接

1.要确保centos7安装了openssh-server,在终端输入yum list installed | grep openssh-server

[root@localhost hjw]# yum list installed |grep openssh-server

我这显示已经安装了,如果没有输出显示表明没有安装,通过输入yum install openssh-server进行安装。

[root@localhost hjw]# yum install openssh-server

2.安装好后,使用vim打开/etc/ssh/下面的sshd_config文件进行更改

[root@localhost hjw]# vim /etc/ssh/sshd_config

编辑打开的文件:

.........
........
Port 22          #将改行前面的#键去掉,开启22端口
#AddressFamily any
ListenAddress 0.0.0.0 #将改行前面的#键去掉
ListenAddress ::      #将改行前面的#键去掉
.......
.........
#LoginGraceTime 2m
PermitRootLogin yes         #将改行前面的#键去掉  允许远程登录
#StrictModes yes
...........
..............
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes     #将改行前面的#键去掉,这是开启用户名和密码登录

保存文件后退出

3.编辑完后要开启sshd服务,输入sudo service sshd start

[root@localhost hjw]# sudo service sshd start
Redirecting to /bin/systemctl start sshd.service

4.检查22端口是否开通,输入命令netstat -an | grep 22

[root@localhost hjw]# netstat -an| grep 22
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN  

  

转载自:https://blog.csdn.net/hjw1314kl/article/details/102968761

posted on 2021-06-18 17:22  SkyLine。  阅读(6503)  评论(0编辑  收藏  举报