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