0% found this document useful (0 votes)
23 views

Linux

Linux concepts

Uploaded by

abreham ashebir
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
23 views

Linux

Linux concepts

Uploaded by

abreham ashebir
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
a How to manage Linux permissions for users, groups, and others How to manage permissions and ownership for users, groups, and all others to resources such as directories and files. Posted: November 26,2020 |? min read Managing access to resources is a fundamental task for sysadmins. This responsibility consists of three components: identities, resources, and permissions. Ths article covers several user, group, and file management commands to control access to resources, The article uses a "How do |." format, and it assumes you have a few resources to work with. Specifically, cover the following topics: + Creating directories and files + Managing ownership and associated groups + Setting permissions with absolute and symbolic modes Linux security «+ Implementing DevSecOns guide Red Hat CVE checker Setting up a playground Ie been in IT for about 25 years, and most of that time was spent as technical trainer. That means that the things that | rite are usually structured as some sort of lab or other hands-on opportunity I's ust how | cover material. With that in mind, llassume you have a couple of identities and resources to experiment with as you read the rest of the article, You can use the following commands to set up a playground. It's best to do this ona virtual machine rather than your personal Linux box, but these tasks are relatively harmless. Create two new users and two new groups to work with, Note that you do not need to configure passwords for the users inthis exercise, as you won't log on with those accounts # usereds user02 # userade user02 # croupacd groups # groupscd groups Note: You would use the passwd user command to set the user's password. [Want to test your sysadmin skills? Take a skills assessment today. ] In your home directory create a new directory named playazound # mkoir playground ‘Change into the ~/p1ayoround directory by using the co command. You are ready to work with the commands and concepts below When you've completed the article and learned the techniques I've covered, delete the two user accounts, the ‘groups, and the playground directory. Use re -£R /playground, userdel user61, and groupdel groupA to remove the resources, How do I create directories and files? Use the nkeir command to create directories. The touch command is one of many ways to create files How do Icreate a directory named Resources? 4H koi Resources How do Iereate a directory path (a series of directories that don't yet exist)? # mkeir —p Resources /data/2020date Note: The goal here's to create the 2628data directory, but the given path’s data directory does not yet exist. The — » option creates parent directories as needed to complete the path How do lereate a file named £4161? # toveh lel How do | create several les at once? # touch file2 f1e3 files How do | manage ownership and groups? In the playground directory display the current owner and group associated with Resources directory and the files, How de | display permission, owners, and groups? His The 1-1 command displays directory contents in long format. The long format contains both permissions and ‘ownership. You can see that the user account that created the resources also owns those resources. The group association is also that user's primary group, [Free download: Advanced Linux commands cheat sheet. J How do Ichange the user/owner associated with £1261? # chown user02 fileL How do Ichange the group associated with £3163? # chown :ezoupé Ciel How do Ichange the owner and group at the same time for £11627 # chown vser02:groupa £162 There is a specific char command, but! prefer only to memorize one command (chown) and apply it to both functions (user and group associations) rather than chown for the user and then have to recall char So how do luse enor? 4 charp groupe filer How do I change the user/group for a directory and all ofits contents? # chown -R user0l:grouph Resources ‘The above task provides a recursive configuration. Technically, recursive commands are repeated on each specified object. Effectively, recursive means "this and everything in it."In the above example, you are configuring the related user/group for the Resources directory and everything init. Without the -R option, you would only affect the Resources directory itself, but not ts contents, [Readers also liked: An introduction to How do | manage permissions? ‘The change mode or chned command sets permissions. The syntax is straight-forward chmod permissions resource-nane Here are two examples of manipulating permissions for £1162: # chmod 740 44162 # hod But wait! Those appear to be radically different examples (they're not, actually). What are all those letters and numbers? We need to discuss absolute mode and symbolic mode. How do | use absolute mode? Absolute mode is one of two ways of specifying permissions. ve seen this mode referred to as octal or numeric ‘mode, but the term] learned was absolute. That term also makes the most sense to me because it's an absolute statement of the desired permissions. always told my students that this seemed lke the most complex of the two ‘modes but is actually the simplest. Usually, they agreed. Each access level (read, write, execute) has an octal value Access level Octal value Read 4 Write 2 Execute 1 Each identity (user, group, others) has a position: Position User First orleft-most Group Middle Others Last orright-most Great Linux resources ‘Advanced Linux commands ‘cheat sheet + Download RHEL 9 at no charge, shrough the Red Hat Developer program + A.guide to installing applications on Linux «Linux system administration skills assessment + How well do you know Linux? ‘Take aquizand get a badge. ‘The absolute mode syntax states the desired permissions from left to right How do I grant the user (owner) read, write, and execute, the group read-only, and all others no access to i162 by using absolute mode? # chmod 140 4162 ‘The three permissions values are associated with identities: uge 740 + The Tis assigned to the user and is the sum of 4+2+1 or readswriterexecute (full access) + The Mis assigned to the group and is the sum of 4+0+0 (read-only) + The O is assigned to others and is the sum of 0+0+0 (no access) In this example, the user has rwx, the group has ronly, and all others have ne access to 1162, Let's look at one more example, How do I grant the user (owner) read and write, the group read-only, and all others read-only to #1162? # chmod 646 file? + The user has 6 (read and write) ‘+ The group has 4 (read-only) + Allothers have 4 (read-only) Lind this easier because there are ne calculations involved. 'm nat concerned with adding or subtracting specific permissions based on the current settings. Instead, | say, “set the permissions to be this,” and that's the end result | get It's an absolute statement [ Free cheat sheet: Get a list of Linux utilities and commands for managing servers and networks. J How do Iset permissions for the Resources directory and all of its contents by using absolute mode? # chmod -R 144 Resources How do | use symbolic mode? ‘Symbolic mode uses more symbols, but the symbo's are simpler to understand. That's attractive to sysadmins that are new to standard Linux permissions, Each access level has a symbol Access lo ‘Symbol Read r Write w Execute x Each identity has a symbol: Identity ‘symbol User v Group 9 Others ° ‘There ate also operators to manipulate the permissions: Task Operator Grant alevel of access . Remove alevel of access - Set a level of access . ‘The general chmod command syntax is the same: conmand permissions directory/tile Here is an example: How do remove the read permissions from others for £1162 by using symbolic mode? 4 chmod o-r #4162 ‘This example removes (-) the read (r) permission from others (0) for £1162. Here's another simple example: How do I grant the read and write permissions to the group for £2162? # chmod grew £3262 This one gives (+) read and write (rx) to the group (0) for £262. How do Iset permissions for a directory and all ofits contents by using symbolic mode? # chmod -R o=Pwe,9 wx Resources Special permissions and Access Control Lists ‘The above discussion covers standard Linux permissions—applying rwx to the user, ‘group, and all others, Linux has far more flexibility, however. Special permissions permit, users to run applications with other credentials, control the inheritance of group associations, and keep files from being changed accidentally. Check out this great article ‘on special permissions Linux also has a way of enforcing different permissions for different users and groups. ‘Access Control Lists (ACLs) permit sysadmins to define permissions for more than just, ‘one user and one group, which adds a great deal more flexibility to standard permissions. “ales rom the fed ‘Asystem administrator's ‘guide tolT automation — F [Bomicndron]

You might also like