To show you in detail "who you are", you may use the command id
:
$ id
uid=1000(alphawolf) gid=1000(alphawolf) groups=1000(alphawolf),4(adm),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),107(netdev),113(lpadmin),128(sambashare),132(wireshark),2000(humans-bc-aw)
As you see, depending on your account the output can get pretty long.
- It does not only display your user name and ID "
uid=1000(alphawolf)
",
- but also the name and ID of your primary group "
gid=1000(alphawolf)
"
and names and IDs of all other groups your account is a member of. This list by default only contains the primary group if you're a normal/restricted user, and a longer list containing at least adm
and sudo
if you're an admin user.
groups=1000(alphawolf),4(adm),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),107(netdev),113(lpadmin),128(sambashare),132(wireshark),2000(humans-bc-aw)
Now, how can we determine our permissions on a file with this information?
We take the output of ls -l /path/to/file-or-directory
, like for example:
$ ls -l /usr/bin/dumpcap
-rwxr-xr-- 1 root wireshark 85632 Aug 16 01:43 /usr/bin/dumpcap*
This file is an executable used by Wireshark to capture network packages with elevated privileges. I chose it because of the different owner and group permissions.
Let's look at the important details:
Owner: root
This is the user owning the file.
Group: wireshark
This is the user group this file is assigned to.
Permission string: -rwxr-xr--
Those are the file permissions for the user, the group members and all others, as described below:
- rwx r-x r--
| \ / \ / \ /
| V V V
| | | \__ Other permissions: [r] 'r'ead access granted
| | | [-] 'w'rite access denied
| | | [-] e'x'ecuting denied
| | \__ Group permissions: [r] 'r'ead access granted
| | [-] 'w'rite access denied
| | [x] e'x'ecuting granted
| \__ Owner permissions: [r] 'r'ead access granted
| [w] 'w'rite access granted
| [x] e'x'ecuting granted
\__ File type: [-] normal file
(alternatives: 'd'irectory, sym'l'ink,
'c'haracter device, 'b'lock device, ...)
Now, what could my user alphawolf
with the id
output above do with this file?
- I am not the user
root
who has full r
ead, w
rite and ex
ecute permissions.
- But I am a member of the
wireshark
group, therefore I have the permissions set for the file's group: I may r
ead the file and ex
ecute it, but not modify it (no w
rite access).
- Others could only
r
ead the file, but neither w
rite to it nor ex
ecute it.
This will help you to determine you permissions on different system files.
whoami
command. Usels -l <file>
to list the user which owns a file (to see who can edit it). Side note: to stop root from owning configuration/temporary files in your home directory, you may want to usesudoedit
instead ofsudo nano
;sudoedit
works exactly likesudo nano
except that it won't let nano write files in your home directory as root.sudo
. Where exactly on the filesystem is the file owned by you? It might be in a directory which allows editing by all users (the directory would look like drwxrwxrwx in ls), which would allow you to create a file owned by yourself.sudo chown root:root <file>
orsudo chown -Rc root:root <directory>
.-R
is recursive,-c
lists all changes. Also check out the answers below from other people, they describe file permissions more in depth if you need that.