Intro to Linux User Accounts and Permissions

0
112
Intro to Linux User Accounts and Permissions

Dit bericht verscheen eerder bij FOSSlife

The chmod program lets you modify file and directory permissions, assuming you are the owner or the system administrator, using either letters or numbers. Here, I’ll concentrate on using letters, because they’re easier to remember.

Using letter notation, u stands for user (owner), g for group, and o for others (all other users). I described previously the meanings for r, w, and x. A combination of these letters (without spaces!) with plus, minus, and equals signs tells chmod to add, remove, or assign these permissions (Table 1). To give the group read and write permissions for a file, type chmod g+rw <file>.

Removing permissions follows the same pattern: The chmod o‑rwx <file> command removes all permissions for all users who are neither the owner nor members in the owner group. You could combine these two commands:

$ chmod g+rw,o‑rwx <file_name>

As I mentioned before, an equals sign lets you assign precisely the permissions specified at the command line. For example, the command

$ chmod ugo=rwx <directory_name>

gives the owner, group members, and all other users read, write, and execute permissions for the directory. Instead of ugo, you could alternatively use a (for “all”) to assign user, group, and other permissions.

To change group membership for files and directories, you can use the chgrp tool. Keep in mind that Linux takes extra precautions with this command: As a “normal” user, you can assign your own files to groups as long as you are a member of the group. As already stated, to see the groups you belong to, you can type groups into a terminal window:

$ groups
editors adm dialout cdrom sudo audio video 
plugdev games users netdev input indiecity

In this case, the user may change access to their own files for members of the groups editors, adm, dialout, cdrom, sudo, audio, and so on. The chgrp command first expects the name of the new group and then the name of the file or directory. To assign a file to the audio group, just type:

$ chgrp audio <file_name>

On a Linux system, the system administrator is allowed to assign new owners and new groups to files and directories. To give a file to user phil, simply use the chown command:

# chown phil <file_name>

Also, you can assign the file to a new group in the same command. To do so, add the name of the group after a colon:

# chown phil:audio <file_name>

The file now belongs to user phil and group audio (see the “Rights of Ownership” box).

Dit bericht verscheen eerder bij FOSSlife

Vorig artikelDPU 101: What are DPUs, what do they do, and who supplies them?
Volgend artikelIntroducing New Capabilities in Microsoft Dev Box