Website-Icon DED9

What is the sudo command? How is it different from the su command?

The sudo and su commands are two common commands in Unix and Linux operating systems that can be used in the command line environment. These two commands have differences regarding managing user access and permissions in the operating system. In this article, we will examine the sudo command and its contrast with the su command.

Su: Allows you to run a command as root but requires knowing the root password. All orders executed with su are not logged. Sudo: Allows you to run a command as root. Depending on the configuration, the order does not require a root password.

The sudo command allows users to gain temporary administrative rights to run commands with administrative access or special access. Using sudo, normal users can temporarily act as system administrators and run otherwise inaccessible commands.

The su command also allows users to fully and permanently switch to the root user account or operating system administrator. Using the su command, users can gain full access to the system by logging in to the root user account and running orders that require administrative access.

The main difference between the sudo and su commands is that by using sudo, a user can gain administrative access temporarily for a specific command. In contrast, by using us, a user can gain administrative access permanently by changing the user account to The root account gains full access to the system.

As we continue reading this article, we will explore the advantages and limitations of each command and what to consider when choosing between sudo or su.

sudo command

sudo, which stands for superuser do or substitute user do, is a command that executes a superuser prompt without requiring impersonation.

Using the sudo command before the command you want to run, you can run that command with elevated administrative privileges without changing your identity. In other words, a regular,  you can run commands as a regular user with administrative access.

Depending on your settings in the /etc/sudoers file, you can issue individual commands as root or as another user. To continue running commands with root, author controls should always use the sudo control. For example, if you want to inst the following all Nginx package, you would run:

$ dnf install nginx

But if you are not root or in the sudo group, you will see an error. Instead, if you run this command:

$ sudo dnf install nginx

You will be prompted for your password, and then you can run the command if you are a member of the sudo group.

A simple way to switch to an interactive session as the root user is:

$ sudo –i

The theory behind using sudo is that issuing sudo before any command you run will make you think more about what you’re doing and hopefully make fewer mistakes with an account with unlimited power.

su command

On the other hand, su stands for switch user or substitute user. You’re switching to a specific user and need a password for the user you’re switching to. Most of the time, the user account you switch to is the root account, but it can be any account on the system.

For example, if you type:

$ su –

In the example above, you are switching to the root account and need the password. The (-) switch gives you the root environment (path and shell variables) instead of giving the root user power for a single command without changing your domain.

$ su Bryant

In the second example, you’re switching to Bryant, so you’ll need the Bryant password unless you’re root.

If you want to switch to the Bryant user account, which includes the Bryant path and environment variables, use the (-) switch:

$ su – Bryant The (-) switch has the same effect as logging in directly with that user account. You become that user.

Why is sudo better than its alternatives?

Sudo is the best and most secure way to elevate access. Let’s take a look at another way of doing things. The “su” switch user command will ask for your root password and give you a superuser command, indicated by the # symbol. This symbol # means “Danger! You are logged in as root!”. The first command you issue may go well. But forgetting you will keep you logged in as root. A lousy typo, and something that shouldn’t happen happens! You’ve wiped the entire hard drive instead of that fake MP3 you downloaded.

Using the sudo command, you must enter “sudo” before each order. You don’t need to be reminded to return to normal user mode, and fewer crashes will occur.

sudoers file

This file is the dark and hidden part of sudo. This file controls who can use the sudo command to gain elevated access. This file is usually located in /etc/sudoers. The best and safest way to edit this file is to use the visudo command. This command will open the vi editor with elevated access for you to edit and save the file. It also locks the sudoers file so no one else can edit it.

After editing is complete, this command checks the file for simple errors. This is a safer way to edit the sudo file than any plain text editor. This file contains many parameters. You can specify which users from which groups can execute which commands. We’re simply going to grant ourselves access to sudo by adding the below:

username ALL=(ALL) ALL //gives user "username" sudo access%wheel ALL=(ALL) ALL //Gives all users that belong to the wheel group sudo access

The specified username will now be able to use all root privileges. You can also allow a user or group to have sudo access to only specific services or servers instead of the ALL parameter.
Difference between sudo and su

When working with Linux, there are two ways to run administrative programs. You can switch to the root user using the “su” command or the “sudo” command. Which one you use depends on the type of Linux you have. Some Linux distributions, such as Fedora, Red Hat, and openSuSE, enable access to the root account, while others, such as Ubuntu and Debian, do not. In this blog, I refer to Ubuntu.

The Unix su command stands for “substitute user,” “super user,” or “switch user” and allows you to log in as root and do whatever you want with the system.

Sudo stands for “substitute user do” or “super user do” and allows you to elevate your current user account to root privileges temporarily.

With ‘sudo’, you’re still using your account, but with root access, while with ‘su’, you’re logged in as root. Also, root access in ‘sudo’ is only valid for a limited time. After that expires, you must re-enter your password to gain root access.

Using ‘sudo,’ you can do almost the same things you can do with ‘su.’ To use it, you need to add “sudo” to the beginning of all root commands. Root user access can be dangerous, but using sudo instead of su can help you secure your system. If you are using Linux and want to do your actions safely, you must know and understand these two commands.

Using the sudo and su commands

Warning: I must warn you here that configuring sudo to allow a user to operate is equivalent to granting root permissions to that user. Before giving sudo power to a user, you are advised to ensure this is appropriate for your security needs.

 

Using the primary form of sudo is very simple. Imagine running the dpkg command to install new software on your computer. If you issue the command dpkg -i software.de as a normal user, you will get an error message informing you that the user does not have the appropriate permissions to run this command. This is because normal users cannot install programs on a Linux machine by default. To install a program on a Linux machine, you must have superuser access. Therefore, to successfully run the installation, you would issue the command sudo dpkg -i software.de instead.

Allow root user access using sudo

In environments where security is a significant concern, I recommend restricting access to the root user account and password. Using sudo, your system administrators will be able to enable root access to users in Ubuntu for specific users (or user groups). Importantly, all commands and arguments will be logged as part of your security protocol and compatibility behavior. Be sure to configure your sudo security policy to log activity. You can do this using the /etc/sudoers file. Inside the sudoers file, configure your user groups and command set to make it easier to check access to the server with sudo commands.

How to create a sudo user in Ubuntu

The sudo command allows you to grant administrative access to regular users from a section of normal users normally only given to the root user. Below I’ll show you the easiest way to create a new user in Linux with sudo access – without having to modify your server’s sudoers file. If you only need to configure sudo for an existing user, skip to step 3.

Steps to create a new user with sudo access:

1. Log in to your Ubuntu server with the root account.

ssh root@server_ip_address

2. Use the “adduser” command to add a new user to the system.

Why is sudo not enough?

Well, now that I’ve given you a brief introduction to su and sudo, you should have an idea of what this command is and how powerful it is. But now unfortunately, I have to disappoint you. You see, while sudo gives you a “convenient” way to manage Virtualization Access Management (PAM), the process is laborious and can lead to increased risk when controlling access in your environment, especially if your environment is large and diverse. be

To use sudo properly requires highly skilled (and highly paid) sysadmins who spend a lot of time creating and distributing sudoers files. sudo also forces you to depend on the individual expertise of your system administrator to program and run it in a way that provides “least privilege”.

Unix/Linux virtual access management (PAM) solutions today offer highly efficient and effective alternatives to sudo. Using these modern approaches, you can reduce the risk of internal fraud, improve regulatory compliance, and drastically reduce the effort required to manage your servers.

5 common problems in using sudo

Here are 5 of the problems that sudo has.

  1. sudo lacks effective and centralized management, which makes system administrators spend a lot of time creating and distributing sudo files on the server.
  2. sudo poses a security risk because it controls local files. Security administrators must distribute these files correctly. Also, the sudo configuration file is saved so local administrators can easily make changes, which is a big security risk.
  3. sudo may cause compliance issues. Auditors are not satisfied with distributed sudo configuration files; Because they use “static trust”. Because of this, your use of sudo may cause problems passing inspections.
  4. Organizations using sudo must be able to distribute the file, so a good distribution practice must be maintained, resulting in more costs for your organization.
  5. sudo does not inherently provide multi-factor authentication (MFA) connectivity as part of the authentication process for authorized users.

In theory, sudo is an acceptable tool, but it has its weaknesses. I recommend using an automated access management system. Unix/Linux authorized access management solutions available on the market today offer highly efficient and effective alternatives to sudo. Using a proper PAM system will significantly improve Unix/Linux server security, simplify compliance with regulatory audits, and experience seamless improvements through improved productivity through simplified management. Proper user privilege management allows you to isolate users and give them only the access they need to perform their tasks.

Conclsion

The sudo command allows users to run commands with administrative access (root) using their user identity. Using sudo, users can run certain commands with Administrator access, without needing to log in to the root account. This security mechanism is used to control user access to system resources.

In contrast, the su (meaning switch user) command allows users to switch to the root account or another account with administrative access. Using the su command, users log in to another user account and execute all commands with root access. This type of user switching may be restricted for security reasons to only users with root access.

So, the main difference between sudo and su is that sudo allows users to run commands with administrative access without needing to log in to the root account, while su allows users to switch to the root account. Regarding the use of sudo and su, it is better to use sudo because instead of sharing the root account’s password, users can run the required commands using their identity, which can improve the system’s security.

Die mobile Version verlassen