Root permissions to users in linux

How do file permissions work for the «root» user?

Can anyone explain to me or point me to a tutorial that explains all of the rules that apply when the root user is dealing with files and directories?

6 Answers 6

Privileged access to files and directories is actually determined by capabilities, not just by being root or not. In practice, root usually has all possible capabilities, but there are situations where all/many of them could be dropped, or some given to other users (their processes).

In brief, you already described how the access control checks work for a privileged process. Here’s how the different capabilities actually affect it:

The main capability here is CAP_DAC_OVERRIDE , a process that has it can «bypass file read, write, and execute permission checks». That includes reading and writing to any files, as well as reading, writing and accessing directories.

It doesn’t actually apply to executing files that are not marked as executable. The comment in generic_permission ( fs/namei.c ), before the access checks for files, says that

Read/write DACs are always overridable. Executable DACs are overridable when there is at least one exec bit set.

And the code checks that there’s at least one x bit set if you’re trying to execute the file. I suspect that’s only a convenience feature, to prevent accidentally running random data files and getting errors or odd results.

Читайте также:  Виртуальная клавиатура кали линукс

Anyway, if you can override permissions, you could just make an executable copy and run that. (Though it might make a difference in theory for setuid files of a process was capable of overriding file permissions ( CAP_DAC_OVERRIDE ), but didn’t have other related capabilities ( CAP_FSETID / CAP_FOWNER / CAP_SETUID ). But having CAP_DAC_OVERRIDE allows editing /etc/shadow and stuff like that, so it’s approximately equal to just having full root access anyway.)

There’s also the CAP_DAC_READ_SEARCH capability that allows to read any files and access any directories, but not to execute or write to them; and CAP_FOWNER that allows a process to do stuff that’s usually reserved only for the file owner, like changing the permission bits and file group.

Overriding the sticky bit on directories is mentioned only under CAP_FOWNER , so it seems that CAP_DAC_OVERRIDE would not be enough to ignore that. (It would give you write permission, but usually in sticky directories you have that anyway, and +t limits it.)

(I think special devices count as «files» here. At least generic_permission() only has a type check for directories, but I didn’t check outside of that.)

Of course, there are still situations where even capabilities will not help you modify files:

  • some files in /proc and /sys , since they’re not really actual files
  • SELinux and other security modules that might limit root
  • chattr immutable +i and append only +a flags on ext2/ext3/ext4, both of which stop even root, and prevent also file renames etc.
  • network filesystems, where the server can do its own access control, e.g. root_squash in NFS maps root to nobody
  • FUSE, which I assume could do anything
  • read-only mounts
  • read-only devices
Читайте также:  Монтирование папки linux nfs

Источник

How to Give Root Privileges to a User in Linux

The “root” super user is the king of users in Linux/Unix. Having root access grants full and unlimited access to the Linux box.

The root or super user has full permission to read(r), write (w) and execute(x) any file. By default root user id is ‘0’.

In this tutorial, I will show you how to allow root access to a user in a Linux system. Typically, root level access is used in system administration. So it is always a pain to give root access to other users. You need to be careful and should withdraw the access once the need to do so is over.

Remember: It’s safer to perform superuser tasks using sudo command than log in as a root account.

I am going to create two users namely user1 and user2. Then I will show you how to give root access to ‘user1’.

Method 1: Adding to Root Group using usermod

Let’s see how we can grant normal user root access by adding to root group.

adduser user1 adduser user2 groupadd test

These are the groups I have in my Linux box.

groups root bin daemon sys adm disk wheel

I am going to add user1 to root group as follows:

The following usermod command given below provides the existing user with the root privilege

Method 2: Adding to Root Group using Useradd Command

I have added a new user, ‘user3’ to the root group using one single command:

useradd -m -G root user3 groups user3 user3 : user3 root

Another option using useradd command

useradd -c “Imitation Root” -d /home/root_user -m -k /etc/skel -s /bin/bash -u 0 -o -g root root_user

Method 3: Editing /etc/passwd file

Edit /etc/passwd for the particular user. Change the user’s UID and GID to ‘0’. This will give root permissions to user.

root:x:0:0:root:/root:/bin/bash temproot:x:128:128:temproot

Now, temproot user should have root privilege:

root:x:0:0:root:/root:/bin/bash temproot:x:0:0:temproot

Note: This is not the recommended method for granting root access

Читайте также:  Linux distros with bspwm

Method 4: Setting as Sudo User

The sudo configuration file is /etc/sudoers and you can edit this file using visudo command: # visudo.

Using visudo protects from conflicts and guarantees that the right syntax is used.

To give full access (grant root privileges) to specific users

Add the entry given below in the file:

Following this method is not a good idea because this allows both bob and tom to use the su command to grant themselves permanent root privileges. Thereby skipping the command logging features of sudo.

Granting access to specific files to one particular user

This entry allows bob and all the other members of the group operator to gain access to all the program files in the /sbin and /usr/sbin directories, as well as the privilege of running the command /usr/oracle/backup.pl.

bob, %operator ALL= /sbin/, /usr/sbin, /usr/oracle/backup.pl

Conclusion

In this tutorial, we learned how to allow root access to a user in a Linux system.

Login in as root and running commands is dangerous because all commands are with the highest privileges. Accident mistakes can even delete root directories and unsafe to run programs with a root shell.

If this resource helped you, let us know your care by a Thanks Tweet. Tweet a thanks

Источник

Оцените статью
Adblock
detector