Open SSH connection on CentOS7 under virtual machine

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

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

It shows that openssh-server has been installed   . If there is no output, it means that   openssh-server is not installed , by entering   yum install openssh-server

to install openssh-server

 

2. Find the   sshd service configuration file  sshd_config in the /etc/ssh/   directory and open it with the Vim editor

Remove the # sign before the listening port and listening address in the file

(Note: 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" after editing to return to the command mode, 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

To check whether the sshd service is enabled, enter ps -e | grep sshd

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

 

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

 

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

 

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

 

7. In CentOS, enter ifconfig to view the network connection address, and find that the network address of CentOS is 192.168.112.128

 

8. In CentOS, enter ping 192.168.30.1 to  test whether the host can be connected, and find that it can be connected

 

9. In the host, enter  ping 192.168.112.128 to test whether the host can connect to CentOS, and find that it cannot be connected

(Note: I don't have China Unicom here, and I can't use the blogger's method. Because it's not the same reason, my problem is that in the network settings of this machine, the Ethernet IP of the virtual machine is set by me to be fixed. In fact, it should be allocated by the router. This is the case here... So change the TCP/IP 4 attribute in Ethernet 3 to automatically obtain an IP address)

If you can connect, you can skip directly to step 12

 

10. On the host, open the network configuration, select the properties of the TCP/IPv4 of the network adapter VMnet8, and perform the network configuration

The subnet mask and default gateway are required to be consistent with CentOS, and the IP address is changed to 192.168.112.1, that is, to ensure that the IP of the host and the IP of CentOS are in the same network segment

 

11. Then in the host, enter  ping 192.168.112.128 , it can be connected

 

12. In the SSH tool (XShell used here), create a new connection, enter the IP address, username and password of CentOS to connect successfully

connection succeeded

 

13. In order to avoid the need to manually start the sshd service every time you start CentOS, you can add the sshd service to the self-starting list and enter systemctl enable sshd.service

(Note: I am using an old version of CentOS 6.3, the command is [root@localhost ~]# chkconfig sshd on Note that [ ...~] indicates the /root path)

You can enter systemctl list-unit-files | grep sshd to see if the sshd service is enabled to start automatically

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325494481&siteId=291194637