Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to modify sshd in centos 7

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you about how to modify sshd in centos 7. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

1. Create a new user wwweee000

[root@localhost ~] # useradd wwweee000 [root@localhost ~] # passwd wwweee000Changing password for user wwweee000.New password:BAD PASSWORD: The password is a palindromeRetype new password:passwd: all authentication tokens updated successfully.

Delete the 2.#Port 22 field and change 22 to other ports that are not used. The maximum server port can be opened to 65536.pm / note that Port is capitalized "P".

[root@localhost ~] # cat-n / etc/ssh/sshd_config | grep "Port *" 17 # Port 22100 # GatewayPorts no [root@localhost ~] # cat / etc/ssh/sshd_config | grep-n "Port *" 17:#Port 22100:#GatewayPorts no [root@localhost ~] # awk "/ Port * /" / etc/ssh/sshd_config#Port 22#GatewayPorts no

The above still does not satisfy the output: we only need the answer of Port 22.

[root@localhost ~] # cat / etc/ssh/sshd_config | grep-n "Port\" 17:#Port 22 [root@localhost ~] # cat-n / etc/ssh/sshd_config | grep "Port\" 17 # Port 22 [root@localhost ~] # cat / etc/ssh/sshd_config | grep-n "Port\" 17:#Port 22 [root@localhost ~] # awk "/ Port\ /" / etc/ssh/sshd_config # Port 22 [root@localhost ~] # sed-I "17s/#Port 22/Port 22bot g" / etc/ssh/sshd_config [root@localhost ~] # awk "/ Port\ /" / etc/ssh/sshd_config Port 22

-n display line number;\ backslash substance definition

3. Modify Port 22 to 4096 without using vi/vim

[root@localhost ~] # sed-I "17s/Port 22/Port 4096 root@localhost g" / etc/ssh/sshd_config [root@localhost ~] # cat / etc/ssh/sshd_config | grep "Port\" Port 4096

4. Change # PermitRootLogin yes to PermitRootLogin no

[root@localhost ~] # cat-n / etc/ssh/sshd_config | grep "PermitRootLogin" 49 # PermitRootLogin yes 104 # the setting of "PermitRootLogin without-password". [root @ localhost ~] # sed-I "49s/#PermitRootLogin yes/PermitRootLogin no/g" / etc/ssh/sshd_ config[ root @ localhost ~] # cat-n / etc/ssh/sshd_config | grep "PermitRootLogin no" 49 PermitRootLogin no

5. Restart the sshd service

[root@localhost ~] # systemctl restart sshd.service

6. Use wwweee000 user login changes

[wwweee000@localhost ~] $

Ordinary user users cannot edit / etc/ssh/sshd_config. You need to switch root to edit. Switch root command: su

7.root to run, write shell script. / / script generic centos 7 (mainly: sshd_config port number definition input forbids root login)

#! / bin/bashsshd_Port= `cat / etc/ssh/sshd_config | grep "Port\" `echo "current sshd port: $sshd_Port" read-ep "Please enter the connection port Port (1-65536) of the sshd service Please make sure other port conflicts and firewall port open business: "sshd_Port_readecho" the port number you entered: $sshd_Port_read "sed-I" s/$sshd_Port/Port $sshd_Port_read/g "/ etc/ssh/sshd_configecho" has been set to: `cat / etc/ssh/sshd_config | grep "Port\" `"sed-I" s/#PermitRootLogin yes/PermitRootLogin no/g "/ etc/ssh/sshd_configsystemctl restart sshd.serviceexit 0

Run the test (can be recycled) this firewall shutdown / production server is off the firewall

[root@localhost wwweee000] # firewall-cmd-- state not running [root@localhost ~] # sh sshd_config_Port.sh current sshd port: Port 22 Please enter the connection port of the sshd service Port (1-65536) Please make sure other port conflicts and firewall ports open business: 4096 the port number you entered: 4096 has been set to: Port 4096 this is how to modify sshd in centos 7 shared by the editor If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report