๐Ÿ”‘๐Ÿš€ DevOps 1.2: All about Sudo! ๐Ÿ’ป๐Ÿ”

Dive deep into the world of sudo with DevOps 1.2! Learn the ins and outs of running secure sudo commands. Get ready to elevate your access control! ๐Ÿš€

ยท

3 min read

๐Ÿ”‘๐Ÿš€ DevOps 1.2: All about Sudo! ๐Ÿ’ป๐Ÿ”

๐Ÿ”‘ Sudo: Superuser Do! ๐Ÿ”’

Sudo is a powerful command in Unix-based operating systems, that allows users to execute commands with elevated privileges or as the "superuser" (root). It stands for "superuser do" and enables authorized users to perform administrative tasks without having to log in directly as the root user.

The use of sudo is crucial for maintaining system security and preventing unauthorized access to sensitive resources. It helps enforce the principle of least privilege by granting temporary administrative access only when necessary, reducing the risk of accidental or malicious actions that could compromise system integrity. ๐Ÿ›ก๏ธ๐Ÿ”’

So, next time you need to perform administrative tasks, remember to use sudo and wield your superuser powers responsibly! โœจ๐Ÿ”‘๐Ÿ‘จโ€๐Ÿ’ป

๐Ÿ’ก Use cases of Sudo: Unleashing Superuser Powers! ๐Ÿ’ช๐Ÿ”ง

sudo -i - Change from normal user to the root user.

๐Ÿค–๐Ÿ” Empower Any User (e.g. Ansible) to Execute Sudo Commands: ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ’ช

If you run sudo in any user which is not present in the sudoers file it will show the below error -

ls -l /etc/sudoers - To know the details about the sudoers file.

As you can see there is no write permission even for the root user.

Do visudo to open the sudoers file in Vim and add the 101st line to the file.

As you can see below we are not getting the error anymore:

If you want to remove the asking for a password which is not required when we are executing scripts in the background then add this to the 101 line. This below line will ensure to not ask ansible for its own password when executing sudo -

NOTE - If there is a syntax error or human error in the sudoers file then it will detect it and ask for an edit.
If you don't have a root user password (generally it is not there due to security reasons) then it will be difficult to fix the error.

๐Ÿ›ก๏ธ๐Ÿ‘ฉโ€๐Ÿ’ป Forge Your Own Sudoers File -

So a better solution is to go to /etc/sudoers. d/ directory and create your own file -

[root@bazinga ~] cd /etc/sudoers.d/
[root@bazinga sudoers.d] ls
vagrant
[root@bazinga sudoers.d] cat vagrant
Defaults:vagrant !fqdn
Defaults:vagrant !requiretty
vagrant ALL=(ALL) NOPASSWD: ALL
[root@bazinga sudoers.d] cp vagrant devops
[root@bazinga sudoers.d] vim devops

[No write since last change]
/bin/bash: line 1: wq: command not found

shell returned 127

Press ENTER or type command to continue
[root@bazinga sudoers.d] cat devops. # percentile to denote it for groups
%devops ALL=(ALL) NOPASSWD: ALL
[root@bazinga sudoers.d] cat *
%devops ALL=(ALL) NOPASSWD: ALL
Defaults:vagrant !fqdn
Defaults:vagrant !requiretty
vagrant ALL=(ALL) NOPASSWD: ALL
[root@bazinga sudoers.d]

So now any user who belongs to group devops can do sudo. It is a safer option than editing the file.

There is more to sudoers file like you can also give special commands to execute in the sudoers file too.

Conclusion:

๐Ÿ”š๐ŸŽ‰ In a world filled with code and commands, you've reached the end of this epic journey! ๐ŸŒŸ๐ŸŒˆ The tale of Sudo, the magical command that grants power, has unfolded before your eyes. ๐Ÿ›ก๏ธ๐Ÿ‘€ From understanding its purpose to exploring its use cases, you've delved into the depths of system administration. ๐Ÿ’ป๐Ÿ”

๐Ÿง™โ€โ™‚๏ธ With the knowledge of Sudo, you can now wield the mighty power to execute commands as a superuser. ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ”ฎ Your path to becoming a tech wizard has been illuminated, and you hold the key to unlocking the full potential of your system. ๐ŸŒ ๐Ÿ’ก

Remember with great power comes great responsibility - "a sudo user"

Did you find this article valuable?

Support Chronicles of Tech ๐Ÿ“š๐Ÿ’ป by becoming a sponsor. Any amount is appreciated!

ย