February 9, 2025
Linux Command Line

Linux Command Line

The “su” command on Linux is a powerful tool for managing users and their permissions. It allows users to temporarily switch to a different user account on the system, or to switch to the superuser account (also known as “root”). In this article, we will explore when and how to use the “su” command, and provide some examples of its usage.

When to Use ‘su’

The “su” command is typically used in situations where a user needs to perform a task that requires elevated permissions, such as installing software, modifying system configurations, or managing other users. For example, a regular user may need to use “su” to switch to the superuser account in order to install a new program, or to change the password for another user.

How to Use ‘su’

Using the “su” command is relatively simple. The basic syntax is as follows:

su [options] [username]
  • Without options and username, it will switch to the superuser account.
  • With options you can specify how the command behaves.
  • With username, you can switch to the account of that user.

When prompted, the user will be asked to enter the password for the target account. If the password is correct, the user will be switched to the new account and will have access to the new account’s permissions and files.

Examples:

Here are some examples of how to use the “su” command:

  1. Switch to the superuser account:
su
  1. Switch to a specific user account:
su john
  1. Switch to the superuser account and execute a command:
su -c "apt-get update"
  1. Switch to a specific user account and execute a command:
su john -c "ls -l /home/john"

What is the difference between “su” and “sudo”?

The “su” and “sudo” commands are both used to switch to a different user account on a Linux system, but they function in slightly different ways.

“su” stands for “switch user” and allows a user to temporarily switch to a different user account, or to the superuser account (also known as “root”), on the system. When a user runs “su,” they are prompted to enter the password for the target account. If the password is correct, the user is switched to the new account and has access to the new account’s permissions and files.

“sudo” stands for “superuser do” and allows a user to temporarily elevate their own permissions to those of the superuser account. When a user runs “sudo,” they are prompted to enter their own password. If the password is correct, the user is given temporary superuser permissions to run a specific command or set of commands.

In summary, “su” is used to switch to a different user account and take on that account’s permissions, while “sudo” is used to temporarily elevate one’s own permissions to those of the superuser account, to perform specific commands. Another important point is that “su” requires the user to know the target account’s password, while “sudo” requires the user to have been granted permissions to use the command by the system administrator.

The “su” command is a powerful tool for managing users and their permissions on Linux systems. By understanding when and how to use it, and practicing with the examples provided in this article, you will be able to effectively utilize the “su” command to manage your Linux system.

See our list of 75 Linux commands you should know about.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Share via
Copy link
Powered by Social Snap