![]() |
|
Users, Groups and Other Linux Beasts: Part 2 - Printable Version +- Sick Gaming (https://sickgaming.net) +-- Forum: Computers (https://sickgaming.net/forum-86.html) +--- Forum: Linux, BSD & Unix (https://sickgaming.net/forum-88.html) +--- Thread: Users, Groups and Other Linux Beasts: Part 2 (/thread-85662.html) |
Users, Groups and Other Linux Beasts: Part 2 - xSicKxBot - 07-16-2018 Users, Groups and Other Linux Beasts: Part 2 ![]() ![]() In this ongoing tour of Linux, we’ve looked at how to manipulate folders/directories, and now we’re continuing our discussion of permissions, users and groups, which are necessary to establish who can manipulate which files and directories. Last time, we showed how to create new users, and now we’re going to dive right back in: You can create new groups and then add users to them at will with the Code: groupaddCode: sudo groupadd photoswill create the photos group. You’ll need to create a directory hanging off the root directory: Code: sudo mkdir /photosIf you run Code: ls -l /Code: drwxr-xr-x 1 root root 0 jun 26 21:14 photosThe first root in the output is the user owner and the second root is the group owner. To transfer the ownership of the /photos directory to the photos group, use Code: chgrp photos /photosThe Code: chgrpNext, run Code: ls -l /Code: drwxr-xr-x 1 root photos 0 jun 26 21:14 photosYou have successfully transferred the ownership of your new directory over to the photos group. Then, add your own user and the guest user to the photos group: Code: sudo usermod <your username here> -a -G photos
sudo usermod guest -a -G photosYou may have to log out and log back in to see the changes, but, when you do, running Code: groupsA couple of things to point out about the Code: usermodCode: -gCode: -GCode: -gCode: -GCode: -GCode: sudo usermod <your username> -a -G photos,pizza,spaceforceSecond: Be careful not to forget the Code: -aCode: -aCode: -GCode: -aNeither of these are catastrophic problems, but it will mean you will have to add your user back manually to all the groups you belonged to, which can be a pain, especially if you have lost access to the sudo and wheel group. Permits, Please! There is still one more thing to do before you can copy images to the /photos directory. Notice how, when you did Code: ls -l /If you read the article I recommended at the beginning of this post, you’ll know that the first d indicates that the entry in the file system is a directory, and then you have three sets of three characters (rwx, r-x, r-x) that indicate the permissions for the user owner (rwx) of the directory, then the group owner (r-x), and finally the rest of the users (r-x). This means that the only person who has write permissions so far, that is, the only person who can copy or create files in the /photos directory, is the root user. But that article I mentioned also tells you how to change the permissions for a directory or file: Code: sudo chmod g+w /photosRunning Code: ls -l /Now you can try and copy an image or, indeed, any other file to the directory and it should go through without a problem: Code: cp image.jpg /photosThe guest user will also be able to read and write from the directory. They will also be able to read and write to it, and even move or delete files created by other users within the shared directory. Conclusion The permissions and privileges system in Linux has been honed over decades. inherited as it is from the old Unix systems of yore. As such, it works very well and is well thought out. Becoming familiar with it is essential for any Linux sysadmin. In fact, you can’t do much admining at all unless you understand it. But, it’s not that hard. Next time, we’ll be dive into files and see the different ways of creating, manipulating, and destroying them in creative ways. Always fun, that last one. See you then! Learn more about Linux through the free “Introduction to Linux” course from The Linux Foundation and edX. |