Check my user permissions linux

How do I know a specified user’s permissions on Linux with root access?

I have root access to my local server. Some days ago, my colleague created a user on that server, giving me the username and password, but the user has minimized permissions. For instance, the user can’t even create a file under its own home directory. Is there any concept about «the permissions of a user»? If there is, how do I check/modify it?

3 Answers 3

It may be the case that your colleague, while creating the account, created the home directory «by hand» which resulted in it being owned by root . Try running the following as root :

chown -R username ~username chgrp -R $(id -gn username) ~username 

Where username is the name of the problematic account.

If this turns out to be your problem, to avoid this happening in the future, you want to add the -m switch to the useradd command line used to create the user account. This ensures that the user’s selected home directory is created if it doesn’t exist. This creates the home directory with the «right» ownership and permissions so you don’t face this kind of issue.

The chgrp command added above will change group ownership of the entire home directory of username to username ‘s primary group. Depending on your environment, this may not be exactly what you want and you’ll possibly need to change group ownership of specific sub-directories inside the home-directory «manually», thereby setting different group ownership for different sub-directories. This is usually not the case for personal computers, but since you mentioned «a colleague», I’m assuming we’re talking about a networked office environment, in which case group ownership is important for shared directories.

Источник

How to Check the Permission of Current Logged In User in Linux

How to Check the Permission of Current Logged In User in Linux 1

In this article, we will see how to check the permission of current logged In user in Linux. If you are a programmer or developer working on a production machine which runs on Linux Operating system then chances are that you will be having some non-root account to login and do your work. Once logged in probably the first question you might ask is what permission do you have in that account ? Whether you are allowed to create or delete some files or not ? Do you have sudo access to perform certain administrative tasks ? All permission sorts of question immediately goes through your mind.

So to answers these kind of questions I am going to give you some very basic but important commands that anyone can run and quickly get an idea about the kind of permission they have. Just to let you know here I am using my Ubuntu 20.04 LTS version to show the demonstration but it does not matter which flavor you are using as all the below command will work in almost all kind of Linux system just fine. Also I am using a non-root user account called cyberithub to login to my System. There is one more user account called john I am using here to explain the usage of chmod and chown command.

Читайте также:  Arch linux lxqt установка

How to Check the Permission of Current Logged In User in Linux

How to Check the Permission of Current Logged In User in Linux

1. Using id command

You can check the current logged In user id and group id using below id command. It will shows all the other group id which you are part of. For example, you can see sudo group here, it means you have sudo access to run privileged command. Similarly you can check what other groups you are in. More about id command.

cyberithub@localhost:~$ id uid=1000(cyberithub) gid=1000(cyberithub) groups=1000(cyberithub),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),120(lpadmin),131(lxd),132(sambashare)

2. Using sudo command

sudo is probably the most important privilege that you need to check. You can use sudo -l command to check all the commands currently logged In user can run. If you see output like below i.e (ALL:ALL) ALL then it means you have unlimited access and you are almost capable of running any command. To check more about sudo command, visit 10 Popular Examples of sudo command in Linux(Redhat/CentOS 7/8).

cyberithub@localhost:~$ sudo -l [sudo] password for cyberithub: Matching Defaults entries for cyberithub on cyberithub: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin User cyberithub may run the following commands on cyberithub: (ALL : ALL) ALL

3. Using umask command

umask is a very important to determine the kind of default permission you have to create files and directories. For example, here when I run umask command, I see 0002 on the output. So this is the default umask value set for my user account. If I want I can change this value using umask command. To known more about how to change umask value, you can check How to change default umask values permanently in Linux.

cyberithub@localhost:~$ umask 0002

As you might be aware to calculate the default directory creation permission you need to subtract this number from 0777 . Once you do that you get 0775 so it means when you create a directory, by default it will have 0772 permission. This can be further understood by creating a simple directory and then checking the permission on that by using below given command. To understand more about permissions, check Concepts of Regular and Special Permissions(SUID and SGID) in Linux

cyberithub@localhost:~$ mkdir hello cyberithub@localhost:~$ ls -ltrd hello drwxrwxr-x 2 cyberithub cyberithub 4096 Jan 22 19:13 hello

Similarly, to calculate the default file creation permission you need to subtract the umask value from 0666. So it will be 0666-0002 = 0664 . It means whenever you will create a file, by default it will have 0664 permission. To prove this, we can create sample file called hello.txt and check its permission by using ls -ltr hello.txt command. You can see that by default it has 0664 permission.

cyberithub@localhost:~$ touch hello.txt cyberithub@localhost:~$ ls -lrt hello.txt -rw-rw-r-- 1 cyberithub cyberithub 0 Jan 22 19:12 hello.txt

4. Using groups command

You can also use groups command to check all the groups you are in. The output you will get here is more or less same like what you saw in id command. But still an important command to remember and check.

cyberithub@localhost:~$ groups cyberithub adm cdrom sudo dip plugdev lpadmin lxd sambashare

5. Using chmod command

Next command that you can use is chmod command to modify the permissions of files and directories. If you want to modify the permission of a file or a directory then you need to use chmod syntax. For example, here we modifying the permission of hello.txt file to 777 using chmod 777 hello.txt command and then confirming it by using ls -ltr hello.txt command as shown below.

cyberithub@localhost:~$ chmod 777 hello.txt cyberithub@localhost:~$ ls -ltr hello.txt -rwxrwxrwx 1 cyberithub cyberithub 0 Jan 22 19:12 hello.txt

But if you try to change the permission of a file which you don’t have access to then you will end up in getting below «Operation not permitted» error. To know more about chmod command, check 11 Popular Unix/Linux chmod command examples to change File Permissions.

john@localhost:/home/ubuntu$ chmod 775 hello.txt chmod: changing permissions of 'hello.txt': Operation not permitted

6. Using chown command

One more command that you can use is chown command to modify the ownership of a file or a directory to another user or group. If you try to modify the ownership of some file which you haven’t created or you don’t have access to then you will end up in getting «Operation not permitted» error. Here I am trying to change the ownership of file hello.txt to user ubuntu and group ubuntu using chown ubuntu:ubuntu hello.txt command. This file was created by user john . To know more about chown command, check 17 Useful Linux chown command examples to change owner and group

john@localhost:/home/ubuntu$ chown ubuntu:ubuntu hello.txt chown: changing ownership of 'hello.txt': Operation not permitted

Источник

Читайте также:  Remove all but one directory linux

How to see the permissions of an user over a file in Linux?

How can I see the permissions of an user over a file (or directiory) in Linux, I know that with «ls -l» I can see the permissions of my user over files. Is there any way to do this with other users without logging in?

2 Answers 2

Actually when you do «ls -l» it return something like that :

-rwxrw-r-- 10 user group 252 Jan 13 08:43:10 text 
  • File permissions
  • Number of links to the file
  • Owner name
  • Owner group
  • File size
  • Time of last modification
  • File/directory name

The file permissions part can be divided in four parts :

  • First character which describe the type of file («-» is for a regular file)
  • Then there is three parts of three characters each :
    • The first is the permissions for the owner of the file
    • The second is the permissions for all the members of the owner group of the file
    • The third is the permissions for everyone else
    • — The file is a regular one
    • rwx The owner is «user» and he has the rights to read («r»), write («w») and execute («x») on the file
    • rw- The group is «group» and every user on that group can read and write on the file but not execute it
    • r— Everyone else can just read the file and cannot write on it or execute it

    To list all the group an user is member of use the command «groups user» (replace «user» by the name of the user).

    The permissions you see on the files when you do ls -l are the permission settings on the file for every user and group on that *nix system. The file permissions settings are universal, and will not change based on which user is logged in to the system. Of course, file permissions of a file or directory can be changed by a user with the correct privileges (and those changes will be universal across every user and group).

    The file permission settings set the permissions controls for three types of entities that may or may not access the file. The three entities are the user, the group, and everybody else. The file permission settings you see when you do ls -l are describing the permissions settings for each respective entity.

    I’d read through this guide to get a better understanding of how permissions work in a *nix system.

    Hot Network Questions

    Subscribe to RSS

    To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

    Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.13.43531

    By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

    Источник

    How do you view file permissions?

    I want to know how to see the permissions a particular file has. Which command should I type in the terminal? However, I don’t want to change it.

    4 Answers 4

    If you want to see the the permission of a file you can use ls -l /path/to/file command.

     ls -l acroread -rwxr-xr-x 1 10490 floppy 17242 May 8 2013 acroread 

    What does this mean ?

    First — represents a regular file. It gives you a hint of the type of object it is. It can have following values.

    • d (directory)
    • c (character device)
    • l (symlink)
    • p (named pipe)
    • s (socket)
    • b (block device)
    • D (door)
    • — (regular file)

    r represents read permission.
    w represents write permission and
    x represents executable permission.

    First combination of rwx represents permission for the owner .
    Second combination of rwx represents permission for the group .
    Third combination of rwx represents permission for the other of the file.

    Octal notation

    Permission of file can also be represented in octal notation.
    In octal notation

    Read or r is represented by 4,
    Write or w is represented by 2
    Execute x is represented by 1.

    Sum of these three is use to represent the permission.

    stat command can be used to view file permission in octal notation

     stat -c "%a %n" acroread 755 acroread 

    For owner it is 4+2+1=7 (111 in binary)
    For group it is 4+0+1=5 (101 in binary) and
    For other it is 4+0+1=5 (101 in binary).

    Источник

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