- Your question: What is root permission in Linux?
- What is root access in Linux?
- How do I give root permission in Linux?
- How do I give root permissions?
- How do I login as root in Linux?
- What is sudo su?
- How do I login as root?
- How do I give a user Sudo permission?
- How do I check if a Linux user has root permissions?
- How do I list users in Linux?
- Understanding Linux File Permissions
- Permission Types
- Explicitly Defining Permissions
- Using Binary References to Set permissions
- Permissions
- Introduction
- Section 2: UNIX permissions explained
- Human-readable form
- The defaults for new files and directories
- Section 3: Modifying file permissions
- Section 4: Example scenarios involving chmod
- Case 1: Family photos
- Case 2: Software and data files for your department at work
- Case 3: Classified files
- Group file sharing scenarios and the limits of basic UNIX permissions
- Access Control Lists in Linux
- Default (inherited) ACL
- Appendix: Some hints
Your question: What is root permission in Linux?
The root user is the user with permissions by default to change ANYTHING in a Linux system. Root is a powerful and dangerous ability in any computer system. I commonly have a root account and a password that is used only for that account. I then use sudo for installation of software and some other duties.
What is root access in Linux?
The root is the user name or account that by default has access to all commands and files on a Linux or other Unix-like operating system. It is also referred to as the root account, root user, and the superuser.
How do I give root permission in Linux?
How to Give Root Privileges to a User in Linux
- Method 1: Adding to Root Group using usermod. Let see how we can grant normal user root access by adding to root group. …
- Method 2: Adding to Root Group using Useradd Command. …
- Method 3: Editing /etc/passwd file. …
- Method 4: Setting as Sudo User.
How do I give root permissions?
Grant Root Permission/Privilege/Access for Your Android Device via KingoRoot
- Step 1: Free download KingoRoot APK.
- Step 2: Install the KingoRoot APK.
- Step 3: Click”One Click Root” to run the KingoRoot APK.
- Step 4:Succeeded or Failed.
How do I login as root in Linux?
You need to set the password for the root first by “sudo passwd root”, enter your password once and then root’s new password twice. Then type in “su -” and enter the password you just set. Another way of gaining root access is “sudo su” but this time enter your password instead of the root’s.
What is sudo su?
sudo su – The sudo command allows you to run programs as another user, by default the root user. If the user is granted with sudo assess, the su command is invoked as root. Running sudo su – and then typing the user password has the same effect the same as running su – and typing the root password.
How do I login as root?
Logging in as root
If you know root’s password, you can use it to log into the root account from the command line. Enter the password once prompted for the password. If successful, you are switched to the root user and can run commands with full system privileges. Be careful while logged in as root.
How do I give a user Sudo permission?
Steps to Add Sudo User on Ubuntu
- Log into the system with a root user or an account with sudo privileges. Open a terminal window and add a new user with the command: adduser newuser. …
- Most Linux systems, including Ubuntu, have a user group for sudo users. …
- Switch users by entering: su – newuser.
How do I check if a Linux user has root permissions?
1 Answer. Yes. If you are able to use sudo to run any command (for example passwd to change the root password), you definitely have root access. A UID of 0 (zero) means “root”, always.
How do I list users in Linux?
In order to list users on Linux, you have to execute the “cat” command on the “/etc/passwd” file. When executing this command, you will be presented with the list of users currently available on your system. Alternatively, you can use the “less” or the “more” command in order to navigate within the username list.
Источник
Understanding Linux File Permissions
Although there are already a lot of good security features built into Linux-based systems, one very important potential vulnerability can exist when local access is granted – – that is file permission based issues resulting from a user not assigning the correct permissions to files and directories. So based upon the need for proper permissions, I will go over the ways to assign permissions and show you some examples where modification may be necessary.
Basic File Permissions
Permission Groups
Each file and directory has three user based permission groups:
- owner – The Owner permissions apply only the owner of the file or directory, they will not impact the actions of other users.
- group – The Group permissions apply only to the group that has been assigned to the file or directory, they will not effect the actions of other users.
- all users – The All Users permissions apply to all other users on the system, this is the permission group that you want to watch the most.
Permission Types
Each file or directory has three basic permission types:
- read – The Read permission refers to a user’s capability to read the contents of the file.
- write – The Write permissions refer to a user’s capability to write or modify a file or directory.
- execute – The Execute permission affects a user’s capability to execute a file or view the contents of a directory.
Viewing the Permissions
You can view the permissions by checking the file or directory permissions in your favorite GUI File Manager (which I will not cover here) or by reviewing the output of the “ls -l” command while in the terminal and while working in the directory which contains the file or folder.
The permission in the command line is displayed as: _rwxrwxrwx 1 owner:group
- User rights/Permissions
- The first character that I marked with an underscore is the special permission flag that can vary.
- The following set of three characters (rwx) is for the owner permissions.
- The second set of three characters (rwx) is for the Group permissions.
- The third set of three characters (rwx) is for the All Users permissions.
- Following that grouping since the integer/number displays the number of hardlinks to the file.
- The last piece is the Owner and Group assignment formatted as Owner:Group.
Modifying the Permissions
When in the command line, the permissions are edited by using the command chmod. You can assign the permissions explicitly or by using a binary reference as described below.
Explicitly Defining Permissions
To explicity define permissions you will need to reference the Permission Group and Permission Types.
The Permission Groups used are:
The potential Assignment Operators are + (plus) and – (minus); these are used to tell the system whether to add or remove the specific permissions.
The Permission Types that are used are:
- r – Read
- w – Write
- x – Execute
So for an example, lets say I have a file named file1 that currently has the permissions set to _rw_rw_rw, which means that the owner, group and all users have read and write permission. Now we want to remove the read and write permissions from the all users group.
To make this modification you would invoke the command: chmod a-rw file1
To add the permissions above you would invoke the command: chmod a+rw file1
As you can see, if you want to grant those permissions you would change the minus character to a plus to add those permissions.
Using Binary References to Set permissions
Now that you understand the permissions groups and types this one should feel natural. To set the permission using binary references you must first understand that the input is done by entering three integers/numbers.
A sample permission string would be chmod 640 file1, which means that the owner has read and write permissions, the group has read permissions, and all other user have no rights to the file.
The first number represents the Owner permission; the second represents the Group permissions; and the last number represents the permissions for all other users. The numbers are a binary representation of the rwx string.
You add the numbers to get the integer/number representing the permissions you wish to set. You will need to include the binary permissions for each of the three permission groups.
So to set a file to permissions on file1 to read _rwxr_____, you would enter chmod 740 file1.
Owners and Groups
I have made several references to Owners and Groups above, but have not yet told you how to assign or change the Owner and Group assigned to a file or directory.
You use the chown command to change owner and group assignments, the syntax is simplechown owner:group filename, so to change the owner of file1 to user1 and the group to family you would enter chown user1:family file1.
Advanced Permissions
The special permissions flag can be marked with any of the following:
- _ – no special permissions
- d – directory
- l– The file or directory is a symbolic link
- s – This indicated the setuid/setgid permissions. This is not set displayed in the special permission part of the permissions display, but is represented as a s in the read portion of the owner or group permissions.
- t – This indicates the sticky bit permissions. This is not set displayed in the special permission part of the permissions display, but is represented as a t in the executable portion of the all users permissions
Setuid/Setgid Special Permissions
The setuid/setguid permissions are used to tell the system to run an executable as the owner with the owner’s permissions.
Be careful using setuid/setgid bits in permissions. If you incorrectly assign permissions to a file owned by root with the setuid/setgid bit set, then you can open your system to intrusion.
You can only assign the setuid/setgid bit by explicitly defining permissions. The character for the setuid/setguid bit is s.
So do set the setuid/setguid bit on file2.sh you would issue the command chmod g+s file2.sh.
Sticky Bit Special Permissions
The sticky bit can be very useful in shared environment because when it has been assigned to the permissions on a directory it sets it so only file owner can rename or delete the said file.
You can only assign the sticky bit by explicitly defining permissions. The character for the sticky bit is t.
To set the sticky bit on a directory named dir1 you would issue the command chmod +t dir1.
To some users of Mac- or Windows-based computers you don’t think about permissions, but those environments don’t focus so aggressively on user based rights on files unless you are in a corporate environment. But now you are running a Linux-based system and permission based security is simplified and can be easily used to restrict access as you please.
So I will show you some documents and folders that you want to focus on and show you how the optimal permissions should be set.
- home directories– The users’ home directories are important because you do not want other users to be able to view and modify the files in another user’s documents of desktop. To remedy this you will want the directory to have the drwx______ (700) permissions, so lets say we want to enforce the correct permissions on the user user1’s home directory that can be done by issuing the command chmod 700 /home/user1.
- bootloader configuration files– If you decide to implement password to boot specific operating systems then you will want to remove read and write permissions from the configuration file from all users but root. To do you can change the permissions of the file to 700.
- system and daemon configuration files– It is very important to restrict rights to system and daemon configuration files to restrict users from editing the contents, it may not be advisable to restrict read permissions, but restricting write permissions is a must. In these cases it may be best to modify the rights to 644.
- firewall scripts – It may not always be necessary to block all users from reading the firewall file, but it is advisable to restrict the users from writing to the file. In this case the firewall script is run by the root user automatically on boot, so all other users need no rights, so you can assign the 700 permissions.
Other examples can be given, but this article is already very lengthy, so if you want to share other examples of needed restrictions please do so in the comments.
If you have anything to add or want to make a comment or correction please do so in the comments. I look forward to your feedback and wish you the best in your future with Linux-based systems.
Источник
- Permissions
Discussion
Introduction
One of key factors to system security is access permissions control. All modern operating systems support this feature. It allows file owners to restrict who can read, write, execute and otherwise change files, running processes and other parts of the system.
Linux, as every UNIX-like OS, has a built-in file permission control system. It assigns the following attributes to every file on its file system:
owner — user who owns the file, has unlimited control over it and can change other file attributes
group — group the file belongs to
UNIX permissions — a set of rules defining who can do what with the file
To see what user and group you are, run id -a in a Shell:
uid: your user name and id
gid: your primary group name and id
groups: all other groups your user belongs to.
If a particular access permission is granted to one your groups, then it will be also be granted to you.
Your effective group id (take into account when creating files and directories, as explained below), is most of the time set to your primary group id.
Page refactoring in progress below this point
Used terms:
file system — an on-disk structure holding descriptions of files (such as the attributes mentioned above, file modification date etc.) and the files’ contents themselves. File systems are contained in disk partitions (also called slices). Most popular file systems today are ext3, xfs and reiserfs. If you run Debian, you probably use ext3. Worth mentioning is the fact that directories (‘folders’) are also considered files, simply containing other files. Therefore, permissions apply to directories, too.
user group — in UNIX-like systems, every user is assigned to some group. Users in the same group may share rights, for example a file’s permissions may be set so that all users in a group can modify its contents.
Section 2: UNIX permissions explained
Having learnt the theory, it’s time to pass on to practice — what do UNIX file permissions look like and how to use them? First of all, let us examine the permissions of an example file. By issuing the following command in Linux console or a terminal emulator:
you will see a list of file’s attributes. It includes file type (it could also be a directory, a symlink, etc.), file size et cetera and a line like the one quoted below, which is the item of our interest:
Obviously, the file is owned by the root user (system administrator) and belongs to the root group. After the slash, numeric user IDs are shown — that’s the way they are stored in the filesystem, in order to conserve disk space.
Access field contains an octal number and its human-readable representation (I personally consider the numeric one to be more readable). It is crucial to know what the permission number means. It consists of four digits, ranging from 0 to 7. For now, we shall skip the first one and focus on the last three, as they are used most commonly on every system. In our example, those are 644. Each digit may be a sum of 4, 2 and 1, but not every component has to be included, giving a possible range from 0 to 7. Below is the meaning of the sum components, with Subject being user, group or others, as discussed below.
- 4 — read permission. Subject is allowed to read the contents of the file or list the content of a directory. Directory content is more than the names of the files, sub-directories, and the other filesystem objects held within each directory; it also includes other meta-information such as whether the filesystem object is a file or directory, the permissions associated with the object, and so forth.
- 2 — write permission. Subject may modify file content. With directories, it allows the subject to modify what’s recorded as being in the directory. This means being able to create files within the directory, or equivalently, move files into the directory; delete files from the directory, or equivalently, move files out of the directory; and, because the directory is where there’s a record of the directory content, to modify the permissions of each file or sub-directory contained in the directory.
- 1 — execute permission. Subject may execute the file. Any file may be marked executable; when the content won’t execute an error is reported at runtime. Likewise any file may have execution privileges removed; files with executable content but no permission to execute can’t be run. In the case of directories, execute permission lets the subject traverse through the directory into sub-directories. Note that directory traversal does not require read permission. See the note on path handling below.
Therefore, number 5, for example, would mean: a permission to read and execute, but not to write.
The digits define respectively: owner, group and others’ permissions. Therefore, we can see that, in our example, file owner (root) may write to the file and read its contents, while group ‘root’ and other users (not being root nor a member of group ‘root’) are given the right to read the file.
Now, compare it to file permissions of /etc/shadow (use ‘stat’ again). This file has 0 as the third meaningful digit, so users not being root nor in group ‘shadow’ may not even read the file. You can easily confirm that by running a text editor and trying to open /etc/shadow — you, as a regular user, should not be allowed to see its contents as it contains system-wide passwords (and this is beyond the scope of this little How To).
Human-readable form
Several system tools and graphical programs recognize the idea of a human-readable form — a string of 10 consecutive characters. To see an example, issue the command below:
The -l flag tells ls to display file permissions in the left column of output. The full sequence that you might encounter is as follows (although you probably won’t find such files in /etc):
Now, let’s divide this into parts. The first character defines node type, which is — for normal file, d for a directory, l for symbolic link, c for a character device, p for a pseudo-terminal and b for a block device. You will find files, directories and links commonly throughout the filesystem, while devices and pseudo-terminals should only appear in /dev. Then we have 3 chunks, 3 characters each: rwx rwx rwx. They directly correspond to respective digits of permissions: if the permission is enabled, you get a letter, and if not, you get — in place of that letter. In this case, the first rwx means 7 to owner, the second is also 7 for owner’s group, and the third is the world (others) permission. Thus, for example, 640 translates to:
(rw- for owner, r— for group, — for others). The last column is the + sign. You are unlikely to see it while listing a directory now (it will appear empty), but it means that extended access rules are in effect, so the file’s real permissions are not only what the file access mode says — you can read about ACL below in this howto.
A note on path handling
To access any path in the filesystem, the user (which the particular process is running as) needs at least execute privilege for all its parent directories. Therefore, if you try to access an example file /etc/security/limits.conf, even though it has a mode of 0755 (for the sake of example), it does not necessarily mean you are free to read it. To read the file, you have to be able to ‘execute’ all of its parent directories, so you need execute permission on /etc and /etc/security. If either /etc or /etc/security has permissions set so that you are not allowed to execute it (1), then reading /etc/security/limits.conf will fail. This rule applies anywhere in the filesystem.
The defaults for new files and directories
This section is included primarily for reference and to aid understanding. Default permissions and group assignment are not often changed so it is safe to skim over this section and come back to re-read it for more detail should the need arise.
The permissions associated with newly created files and directories are, for the most part, determined by something called a umask. The umask is a 4 digit octal number that is subtracted from 0777 to produce the default permission associated with objects newly created in the filesystem. The umask of a ‘stock’ Debian system is 0022 which makes the default permissions be 0755 — the owner has all permissions, the group read and execute but not write, and everybody else can read and execute but not write. One would then expect all newly created files to be marked executable but this is prevented because the system call that creates files defaults to creating files that are not executable. Directories on the other hand do have their execute bit set, umask permitting, and so by default can be traversed by all.
The shell umask command can usually be used (without any arguments) to display the current default umask. The umask is set globally by the system administrator in one of various ways; the most elegant is probably the use of the ?PAM pam_umask module in /etc/pam.d/common-session. The system-wide umask may be overridden by each user. This is usually done in
/.bashrc on a per-user basis, with the shell umask command on a per-process basis, or using the umask(2) system call from within a program.
The user uid (user id number) associated with a newly created file or directory is that of the running process effective uid. In most cases this is the uid of the user who logged in and started the process.
The group associated with a newly created file or directory is the effective group of the running process. This is normally the group named with the username of the logged in user, but can be manually changed (along with the «real» group) on a per-process basis with the newgrp command although this is rarely done.
The first of the 4 octal digits which represent permissions contains the setuid and setgid bits. These can be used to override some of the defaults described above but it is not worth getting into details other than to note that the user private groups project collaboration idiom (see below) depends on the behavior of the setgid bit.
Section 3: Modifying file permissions
This section shows, using an example, the very basic usage of chmod command. Chmod is one of sysadmin’s best friends and the standard tool for manipulating file permissions in various Unices (also works with *BSD and Solaris!). Let’s begin. First of all, create a file for demonstration purposes. In the example, I will be using name testfile. Commands below are to be executed in a terminal emulator or Linux console. You can just copy and paste, and see how it works.
There is a special case: to clear special bits with directories, you must mention the file mode bits explicitly (in symbolic mode) or by operator numeric mode (in octal description) (see more with: ‘info coreutils, section 27.5 «Directories and the Set-User-ID and Set-Group-ID Bits»)
Have the file permissions changed? You can verify that it actually worked by starting a new session and logging on to another user account, or issuing su username. If you only have one user account, create a new one for testing:
Now, log on to demo, open testfile (in your regular user’s home directory) and type something in it. Save, and then check with your own user’s account that it contains whatever you may have written. Voila! You may now want to check it with various different permissions. Try chmod with arguments like 644, 640 and so on.
Section 4: Example scenarios involving chmod
You now know how to change file permissions. However, how can they be useful in real life besides letting your buddy leave you a random message in your own text files?
Case 1: Family photos
Situation: You store family photos in directory Photos on your user account. Several other family members use the computer and you want them to be able to access the photos.
Question: How to set directory permissions so that other users can see your files and their content?
Answer: Set the directory to 755 and all files under it to 644:
Case 2: Software and data files for your department at work
means your home directory.
Situation: In your home directory you have a program in
/AppSoftware/program.bin . It stores your department-specific data files in
/OurData. The system operator has assigned you and other people in your department a user group ‘mydept’. You want other people from your department to be able to run the provided software and to write the data files. At the same time, other people from outside the group should be allowed to run the software but not to modify the data. For simplicity’s sake, we skip things like logging who added/removed what in terms of data (logging is a necessity in real life), focusing only on appropriate permissions.
Question: How to allow execute access for a group to one file (program binary) and read-write access to other directory for the same group, while denying world (other users) access?
Answer: In our example, this would be:
In case files have a wrong group attribute set, you can correct it by first running chgrp -R mydept files, where ‘mydept’ is the group name, ‘files’ is file path, and -R switch tells chgrp to run recursively (see above code example). Chgrp changes files’ group to the one given.
Case 3: Classified files
Question: How to protect files that are to be kept secret?
Answer: A very basic protection can be achieved by chmodding the sensitive files/directories to 0600. However, remember that the system administrator (root) can still access them, regardless of set file permissions. Therefore, besides locking down file permissions, it is highly advisable that you encrypt the files using strong encryption software (try OpenPGP encryption via programs like KGpg, or see ccrypt — symmetric cryptography).
Group file sharing scenarios and the limits of basic UNIX permissions
Examples above show the usefulness of UNIX file permissions. You can grant users from your group access to your files, expose them to the whole world or have them only for yourself. However, there are use cases in which this access control model is not enough. Assume that you are on a large system (perhaps a server) and, together with several dozen users you are members of group ‘users’. Now, you want to make some of your files available to just one of them so that the others can not read it. How can UNIX permissions benefit you? You could use the user private groups directory sharing idiom; a common solution to this problem. But the user private groups idiom pushes the UNIX permission system to its limits and there are cases, even simple file sharing cases between 2 people, where the idiom is simply not suitable.
When the limits of basic UNIX file permissions are reached it is time to make use of.
Access Control Lists in Linux
Access Control Lists (called ACL) are an extended means of defining access rights to files and objects. They allow you to specify file permissions in a more fine-grained way, assigning any user or group (besides owner and file’s set group) different privileges. For instance, you may share a file with just one specific user, no matter what group they are in. How to make use of this new, powerful feature?
First, make sure your system supports ACL. Several criteria must be met before you can enable ACL for your files. Check your kernel version. If it is anything later than 2.6.18, then chances are you already have ACL support built-in. (I’m not quite certain at which version Debian kernels received the ACL patch). The next thing is acl package, required for ACL attribute manipulation. You can install it by issuing:
Alternatively, you can use Synaptic package manager, or another package manager, to get and install the package. If you are not the system administrator, ask your sysadmin to enable ACL on your machine.
Once you have installed acl, you can try and see if your file system supports it. Example command (I assume that file ‘testfile’ exists):
If setfacl complains about an error, you probably need to mount your filesystem with acl option. Assuming that the filesystem ‘testfile’ is located on is / , execute the below as root:
Try setfacl again. If successful, a call to:
should show, among others, a line like this:
user:demo:r-x
Here, rx means ‘read, execute’ permission, which is equivalent to 5. To see if Access Control Lists work, set the file permissions on testfile to 700 using chmod and try to open it from ‘demo’ user account. If successful, ACL did override UNIX permissions indeed. Your file system is now ready for granular access control with ACL!
Note: To enable ACL permanently for certain filesystems, you should include acl option in /etc/fstab. Please refer to fstab(5) manual page for instructions.
Example uses of setfacl to manage file permissions
Default (inherited) ACL
Note: a bug in coreutils commands cp and mv limits the scope of the below to pure file creation, e.g. with touch: with copy and move, the «Default mask» of the target parent directory won’t be inherited as the «Access mask» for the copied/moved file/directory: http://debbugs.gnu.org/db/85/8527.html
Default ACL are an invaluable tool when making a directory that you want to share for reading or writing among users. This hint is inspired by this thread on the Debian forums: http://forums.debian.net/viewtopic.php?f=10&t=53591
Default ACL are access control entries that get inherited by all sub-items of a directory (recursion deeper is allowed!). Thus, if you want to create a directory for bob and fred so that both can work on each other’s files, the below should suffice (notice the -d flag to setfacl, it sets a default ACL):
Note to the above: a default ACL is inherited by all child nodes as an ACL entry and default ACL, but a default ACL on its own does not take any action permission-wise — hence the double command. The first call gives user ‘bob’ the right to write, read and execute the directory, and the second one sets up the default ACL which will be inherited.
Now, whenever a file gets created, it retains its original owner and group, but should automatically get assigned the above ACL. This is, for example, useful when you have users co-working on website development. You can use Apache or PHP running as www-data, write a script to change file ownership upon creation to www-data (inotify helps!), and all files are still writable by bob and fred, your Web developers.
Appendix: Some hints
- On Debian systems, every user is traditionally assigned their own group. File sharing may be accomplished by adding one user to other’s group, as shown below (only to be done as root):
Then, ‘otherguy’ can just set their files to 0750 or whatever permissions they want you to have. However, this is the old-fashioned approach to granular file permissions and should be avoided whenever possible in favour of user private groups or ACLs.
Konqueror (at least in Debian Squeeze) supports ACL out-of-the-box when filesystems are mounted with acl option. It allows for easy, graphical management of extended access rights, similar to that of Microsoft Windows.
Sometimes you have to mount a filesystem that does not support ACL. For example, a NFS volume exported by a central storage solution, or an userspace zfs diskset. In these situations, you can try one simple solution: http://cintrabatista.net/nfs_with_posix_acl.html
You can find a wonderful but pretty old (still current, though) ACL guide here: http://www.vanemery.com/Linux/ACL/linux-acl.html
That’s all! Have fun and thanks for bearing with me.
Источник