1. Prepare the openssh server. –

Run the following command to check whether openssh-server is installed. If openssh-server is installed, the corresponding information is displayed

/ root @ sagecat ~ # yum list installed | grep openssh openssh. X86_64 p1-21. 7.4 el7 @ anaconda openssh - clients. X86_64 7.1-21.el7@anaconda openssh-server.x86_64 7.1-21.el7@anaconda Openssh-server.x86_64 7.1-21.el7@anacondaCopy the code

If it is not installed, run the following command to install it as prompted

[root@sagecat ~]# yum install openssh-server
Copy the code

2. Modify the configuration file

After openssh-server is installed, modify the sshd_config file in /etc/ssh and open it with vim. If vim is not installed, enter yum install vim.

vim /etc/ssh/sshd_config
Copy the code

Find the following code sections and modify or uncomment the following four sections

Port 22
#AddressFamily anyListenAddress :: #
# Authentication:
#LoginGraceTime 2mPermitRootLogin yes # Cancel the previous comment#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

# To disable tunneled clear text passwords, change to no here!PasswordAuthentication Yes # Uncomment#PermitEmptyPasswords no
Copy the code

Enter the vim command mode and enter wq! Exit and save the configuration

3. Restart the SSHD service and check whether it is running properly

Run the following command to restart the SSHD service

[root@sagecat ~]# systemctl restart sshd
Copy the code

Run the following command to check whether the SSHD service is running. If the command output is displayed, the SSHD service is running properly

[root@sagecat ~]# ps -e | grep sshd
  1050 ?        00:00:00 sshd
  1446 ?        00:00:00 sshd
Copy the code

Run the following command to check whether port 22 is being listened to. If any information is displayed, port 22 is being listened. If the message netstat command not found is displayed, enter yum install net-tools to install the NET tool

/ root @ sagecat ~ # netstat - an | grep 22 TCP 0 0 0.0.0.0:22 0.0.0.0: * LISTEN TCP 0 36 192.168.150.128:22 192.168.150.1:1446 ESTABLISHED tcp6 0 0 :::22 :::* LISTENCopy the code

4. View the IP address of the CentOS server and remotely access it from another machine

Run the ifconfig command to query the IP address of the server. For example, ens33 is the name of the network adapter of the server, and 192.168.150.128 is the IP address of the server

[root@sagecat ~]# ifconfig ens33: Flags = 4163 < UP, BROADCAST, RUNNING, MULTICAST > mtu 1500 inet 192.168.150.128 netmask 255.255.255.0 BROADCAST 192.168.150.255  inet6 fe80::af35:e43f:eb07:503 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:24:ba:49 txqueuelen 1000 (Ethernet) RX Packets 2409 bytes 490350 (478.8kib) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2729 bytes 3564820 (3.3 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: Flags =73<UP,LOOPBACK,RUNNING> MTU 65536 inet 127.0.0.1 netMask 255.0.0.0 inet6 ::1 Prefixlen 128 scopeid 0x10<host> loop Txqueuelen 1000 (Local Loopback) RX packets 64 bytes 5568 (5.4Kib) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 64 bytes 5568 (5.4 KiB) TX errors 0 dropped 0 overruns 0 Carrier 0 collisions 0Copy the code

Pass on another Windows computerPuttyorXShellTo remotely access the CentOS serverXShellFor example, after establishing a new connection, enter the user name and password to enable remote access.


Attached: Method of modifying the host name

What is a host name? If you do not specify a host name when you install CentOS, the default may belocalhost

Simply change the contents of hostname in the /etc directory

[root@sagecat ~]# vim /etc/hostname
Copy the code

You will see the following, delete this line, change it to the name you want and save it. For example, mine is Sagecat, remember not to comment the first line with #, then add the name you want on the second line! Because this file inside is not support comment, pro test!

Save it and it will take effect after the next server startup.

localhost.localdomain
Copy the code

If you find this article helpful, please like it and follow it!