首页 > 其他 > 详细

开启ssh服务

时间:2020-12-04 08:59:43      阅读:56      评论:0      收藏:0      [点我收藏+]

openssh-server工具

功能

       主要是作为一个服务运行在后台,如果这个服务开启,我们就可以用一些远程连接工具来连接centos。
       让远程主机可以通过网络访问sshd服务,开始一个安全shell



安装软件

   查看openssh-server工具是否安装      
  [root@aubin aubin]# yum list installed |grep openssh-server
openssh-server.x86_64                       7.4p1-21.el7               @base   
   
   
   若没有,在有网的情况下安装openssh-server工具
        yum install openssh-server



注:linux下vim 查找命令: /text --查找text, 按n查找下一个, N查找上一个
查询时不区分大小写 :/查询内容\c

安装软件

修改

#   Port  22                             默认端口号,我们也可以修改 2246
#   permitRootLogin no /  yes      同意/ 拒绝root用户远程登陆
#
#   ListenAddress 0.0.0.0      监听的主机适配卡!,如果您有两个 IP,分别是 192.168.0.100 及 192.168.2.20 ,那么只想要开放 192.168.0.100 时,就可以写如同下面的样式: 
#   ListenAddress 192.168.0.100     只监听来自 192.168.0.100 这个 IP 的SSH联机。如果不使用设定的话,则预设所有接口均接受 SSH
#   PasswordAuthentication yes  开启用户~用户名密码来作为连接验证
 开启  sshd  服务
 
 [root@aubin aubin]# systemctl status sshd
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since 四 2020-12-03 23:27:58 CST; 4min 27s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 12445 (sshd)
    Tasks: 1
   CGroup: /system.slice/sshd.service
           └─12445 /usr/sbin/sshd -D

12月 03 23:27:57 aubin systemd[1]: Starting OpenSSH server daemon...
12月 03 23:27:58 aubin sshd[12445]: Server listening on 0.0.0.0 port 22.
12月 03 23:27:58 aubin sshd[12445]: Server listening on :: port 22.
12月 03 23:27:58 aubin systemd[1]: Started OpenSSH server daemon.

 
 
 


检查  sshd  服务是否已经开启
[root@aubin aubin]# ps -e |grep sshd
 12445 ?        00:00:00 sshd
 
 
 
 检查  22 号端口是否开启监听
 [root@aubin aubin]# 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     
udp        0      0 192.168.122.1:53        0.0.0.0:*                          

使用MobaXterm连接ssh

1.在Vmware Workstation中,查看CentOS7的属性,发现网络连接方式是采用的 NAT 方式连接的 2.在Vmware Workstation中,点击编辑=》虚拟网络编辑器,进入虚拟网络编辑器,查看发现 NAT 模式的连接采用的网络适配器名称为VMnet8 3.在 windows 主机中,在命令行中输入ipconfig 查看主机IP,找到 VMnet8 的连接信息,此处 ip 为192.168.10.1
以太网适配器 VMware Network Adapter VMnet8:

   连接特定的 DNS 后缀 . . . . . . . :
   本地链接 IPv6 地址. . . . . . . . : fe80::8080:c5f5:beb:893b%7
   IPv4 地址 . . . . . . . . . . . . : 192.168.10.1
   子网掩码  . . . . . . . . . . . . : 255.255.255.0
   默认网关. . . . . . . . . . . . . :

4.在CentOS中,输入ifconfig查看网络连接地址,发现CentOS的网络地址为192.168.10.150

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.150  netmask 255.255.255.0  br

5.windows ping VMnet8的ip 192.168.10.150 能ping通;而centos7 ping Windows ip 192.168.10.1 ping不通
6.如果要配置:要求子网掩码、默认网关均和CentOS一致,并将IP地址修改为 192.168.112.1,即保证主机的 IP 和 CentOS 的 IP 在同一网络区段中
7.
8.打开SSH工具(此处使用的MobaXterm)中,新建连接,输入 CentOS7 的 IP 地址、用户名、密码即可连接成功

9.将 sshd 服务添加至自启动列表中

[root@aubin sdb1]# systemctl enable sshd.service

10.查看是否开启了sshd 服务自启动

[root@aubin sdb1]# systemctl list-unit-files | grep sshd
anaconda-sshd.service                         static  
sshd-keygen.service                           static  
sshd.service                                  enabled 
sshd@.service                                 static  
sshd.socket                                   disabled

未完待续。。。

参考文档

https://www.cnblogs.com/dumpling-z/p/11434105.html
https://www.cnblogs.com/kinwing/p/11134179.html

开启ssh服务

原文:https://www.cnblogs.com/xwdzj/p/14083694.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!