Our latest blog offers the steps to add user to sudoers via command line in Almalinux. As part of our Server Management Service, Bobcares provides answers to all of your questions.
Adding User to Sudoers via Command Line in Almalinux
The 2 different methods to add a user to the sudoers file via the command line in AlmaLinux are as follows:
1. With CLI Commands
1. Initially, use SSH or the server’s console to access the server. Make sure we have root or admin privileges.
2. Run: su –
3. Enter the root password when prompted.
4. Run: useradd bobcares. This creates a new user named “bobcares”.
5. Run: passwd bobcares
6. Enter and confirm the new password for “bobcares”.
7. Run: usermod -aG wheel bobcares. This adds “bobcares” to the “wheel” group, which has sudo privileges.
8. Switch to the new user: su – bobcares
9. Test sudo access: sudo ls /root
10. If prompted for a password and the command works, sudo is set up correctly.
11. Now, open the SSH config file: nano /etc/ssh/sshd_config
12. Change PermitRootLogin yes to PermitRootLogin no
13. Save and exit the file.
14. Run: systemctl restart sshd. This applies the new SSH settings.
2. By Editing the Sudoers File
1. Open the Sudoers File
2. Run: sudo nano /etc/sudoers. This opens the sudoers file for editing.
2. Find the line: # %wheel ALL=(ALL) ALL and remove the # to enable it.
3. Add: bobcares ALL=(ALL) ALL. This gives “bobcares” full sudo access.
4. Press Ctrl+X, then Y, then Enter to save and exit.
5. Switch to the new user: su – bobcares
6. Test sudo access: sudo whoami. If the command returns “root”, sudo is set up correctly.
By following these steps, we’ve successfully created a user with sudo privileges on the AlmaLinux server.
[Searching solution for a different question? We’re happy to help.]
Conclusion
To sum up, our Experts went over the details of adding user to sudoers via command line in Almalinux
var google_conversion_label = "owonCMyG5nEQ0aD71QM";
0 Comments