Home »
Linux
Linux sudo, su, and chmod Commands
Linux sudo Command
The sudo command stands for "superuser do" & also know as "sudoers". Sudoers file maintains by the system administrator, who allows to access rights for some commands to particular users. sudo command prompts for root password before executing commands. Without knowing root password, anyone can not access those commands which are available in sudoers file.
Syntax
sudo command-name
If you are trying to update your system, using apt-get update command. You can not execute this command with out using sudo before it.
Example
ih@linux :~ apt-get update
could not open lock file var/lib/apt/lists/lock -open (13: permission denied)
The command will not execute, permission denied message displays. To run successfully use sudo before apt-get update command.
Example
ih@linux :~ sudo apt-get update
Linux su Command
The su cmmand standrs for "switch user". The su command helps us to switch current user to another. Just type the user-name after the su command, it will ask for the password (target user's password).
The su is also switches to root account.
Example
To switch root account:
myLinux :~ su
Password:
After entering the correct password, you can access root account. Now you can also execute each sudoers command without using sudo command.
Linux chmod Command
The chmod command stands for "change mode", it is used to assign permission to the file/directory for different users.
There are following users on which you can assign directories/files access rights.
- Owner of the file
- The members of a group of related users
- And others
There are following permissions, that can apply on a file/directory.
- r - Allow to read the file
- w - Allow to write into the file
- x - Allow to execute the file
Permissions can be assigned using -rwx rwx rwx
Here,
- rwx : read, write, and execute permissions for the owner of the file
- rwx : read, write, and execute permissions for the group owner of the file
- rwx : read, write, and execute permissions for all other users
With chmod command, you can use following set of permissions, to apply desired conditions on a file/directory.
Example
rwx rwx rwx = 111 111 111 [ chmod 777 file-path ]
rw- rw- rw- = 110 110 110 [ chmod 666 file-path ]
rwx --- --- = 111 000 000 [ chmod 700 file-path ]
and so on...
rwx = 111 in binary = 7
rw- = 110 in binary = 6
r-x = 101 in binary = 5
r-- = 100 in binary = 4
example:
chmod 777 /home/file1.txt