Create a New User Grant Root Privileges and Disabl SSH Root Login on CentOS
Question
Recently, we encountered the problem that Alibaba Cloud ECS server was attacked by DDoS, indicating that our server security needs to be improved. From the perspective of ssh login, you can set sub-users for the linux system and prohibit root login, which can improve certain security.
In this article you will learn
- How to create a new user and set a password for linux system and CentOS system
- How to grant permission control to new CentOS users
- How to prohibit root login to improve server ssh remote connection security
- How to restart sshd service
- How to view file permissions and modify file permissions
User Management
Create a user and set a password
First create a user, give a name, such as
lwebappadduser lwebappSet a password for the user
lwebapp, it will trigger interaction, just enter the passwordpasswd lwebapp # Trigger interaction, enter password lwebappwdGrant root privileges Modify
sudoersto give root privileges to the newly created user, so that every time you only need to log in with the new userlwebapp, all server operations can be completed.The
sudoersfile is in the/etcdirectory, first modify the permission of this file to allow modificationchmod 777 /etc/sudoersThen open with
vimHit
ito enter edit modevim /etc/sudoersThen after the
root ALL=(ALL) ALLline break, enterlwebapp ALL=(ALL) ALL # Give all permissions to lwebapp, same as root aboveHit
Esc, enter colon:to enter vim command mode, then enterwq, hitEnterto save and exitAfter saving the file, set the file permissions back
chmod 444 /etc/sudoersDisable root login Because of the new user, the root user's login authority is prohibited, so that hackers cannot operate the server by cracking the root login. At least our new user name has changed, which adds a layer of difficulty to hacker attacks.
Locate and edit the
sshd_configfilevim /etc/ssh/sshd_configFind
PermitRootLogin yes, changeyestono, which means that the root account is not allowed to log inPermitRootLogin noRestart sshd Finally restart sshd to take effect
systemctl restart sshd.service
Extended Learning
File Permissions
Check file permissions
stat -c '%A %a %n' *Make all files in a folder have 777 permissions
chmod 777 -R ./webapps
vim basic operations
Open a file
vim file.txtEnter edit mode
Hiti, the bottom of the terminal interface displays-- INSERT --is the edit modeEnter command mode
Enter:, the bottom of the terminal interface displays:and the cursorExit edit mode or command mode
HitEscSave and exit
In command mode, enterwq, hitEnterto save and exitForce Quit
In command mode, enterq!and hitEnterto complete the forced exit
sshd service
View sshd service status
systemctl status sshd.serviceA series of service statuses will be displayed, such as
running, which means that the startup is successful.Start the sshd service
systemctl start sshd.serviceRestart the sshd service
systemctl restart sshd.serviceSet to start at boot
systemctl enable sshd.service

Comments