Open SSH connection on CentOS7 under virtual machine (mainly network configuration sshd download)

After pointing, I found the following article, thanks to the blogger:

http://blog.csdn.net/trackle400/article/details/52755571


================== The following is transferred from the blogger ====================

Under the virtual machine (Vmware Workstation), CentOS7 is installed, and now I want to connect to CentOS7 in the virtual machine through the SSH tool


Note

1、

The centos ifconfig command needs to be reinstalled  

yum install net-tools
2、

sshd service yum install openssh-server



1、 First, make sure that   openssh-server is installed on CentOS7 , enter in the terminal  yum list installed | grep openssh-server

Here it shows that openssh-server has been installed   , if there is no output showing that   openssh-server is not installed , enter   yum install openssh-server

To install openssh-server


2、 Found   the sshd service configuration file  sshd_config in the /etc/ssh/   directory , and opened it with the Vim editor

Remove the # in front of the listening port and listening address in the file

(Remarks: The blogger has omitted some operation methods. As a rookie, I still add vim to enter the text, press "i" to start editing, press "esc" to return to the command mode after editing, press ":wq" to save and exit )

Then enable allow remote login

Finally , enable the use of username and password as connection authentication

save the file, exit


3、 To start the sshd service, enter  sudo service sshd start

Check if the sshd service is enabled, enter ps -e | grep sshd

Or enter netstat -an | grep 22   to check   whether port 22  is listening


4、 In Vmware Workstation, check the properties of CentOS7 and find that the network connection mode is connected by   NAT   mode


5. In Vmware Workstation, click Edit = " Virtual Network Editor , enter the virtual network editor, check and find that the network adapter name used for the connection in NAT mode is VMnet8


Pay attention to check


6In the windows host, enter ipconfig  on the command line to view the host IP, and find the connection information of VMnet8, where the ip is 192.168.30.1


7在CentOS中,输入ifconfig查看网络连接地址,发现CentOS的网络地址为192.168.112.128


8在CentOS中,输入ping 192.168.30.1 测试是否能连通主机,发现可以连通


9在主机中,输入 ping 192.168.112.128,测试主机是否能连通CentOS,发现连不通

(备注:我这边也没联通,用了博主的方式也不行,因为不是同一个原因,我的问题在于本机的网络设置中,虚拟机的以太网IP被我设置成固定的了, 其实应该是由路由器分配的,这边的情况是这样...所以将以太网3中TCP/IP 4属性改为自动获取IP地址)

如果可以连得通,可以直接跳至第12 步


10、在主机,打开网络配置,选择网络适配器 VMnet8 的  TCP/IPv4   的属性,进行一下网络配置

要求子网掩码、默认网关均和CentOS一致,并将IP地址修改为 192.168.112.1,即保证主机的  IP  和  CentOS  的  IP  在同一网络区段中


11、再在主机中,输入 ping 192.168.112.128,已经可以连接得通了


12、在SSH工具(此处使用的XShell)中,新建连接,输入  CentOS   的  IP  地址、用户名、密码即可连接成功

连接成功


13、为了免去每次开启 CentOS 时,都要手动开启  sshd 服务,可以将 sshd 服务添加至自启动列表中,输入systemctl enable sshd.service

(备注:我用的是CentOS 6.3 版本老,命令是[root@localhost ~]# chkconfig sshd on  注意[ ...~]表示的是/root路径)

可以通过输入systemctl list-unit-files | grep sshd,查看是否开启了sshd 服务自启动

Guess you like

Origin blog.csdn.net/qq_34068440/article/details/78054600