Slides on how to control access to files - Part of RHCSA (RH124) syllabus
Size: 828.07 KB
Language: en
Added: Sep 19, 2024
Slides: 21 pages
Slide Content
Control Access to Files
File Permissions
●Safeguard data from unauthorized access or modification
●Use "-l" option in "ls" command to display detailed
information about files and directories.
●Access controls:
○Who can access a file or directory.
○What actions they can perform on them.
●Changes the permissions (r,w,x) of files and directories.
●Syntax: chmod [options] permissions file(s)
Change permission in symbolic mode
○Command: chmod u+x books.txt
Change permission in numeric mode
○Command: chmod 755 library
chmod
●Changes the owner and group ownership of files and
directories.
●Syntax: chown [options] new_owner file(s)
●‘-R’ option on a directory changes ownership of all the files
in the directory.
Change ownership of a file
○Command: chown user1 file.txt
Transfer ownership and group ownsership
○Command: chown user2:group2 demoFile.txt
chown
●Changes the group ownership of files and directories.
●Syntax: chgrp [options] new_group file(s)
Change group ownership
○chgrp group2 file.txt
●The -R option makes the command recursive.
chgrp
●Set default permissions for newly created
files and directories in Linux
●umask values are 4 digit octal numbers
●umask values (umask 0022) are
subtracted from default permissions
●Default permission: 666 for files & 777 for
directories
●1
st
digit in umask represents additional
attributes (sticky bit, setuid, & setgid)
umask
Get umask value
○ Command: umask
Set umask value
○Command: umask 0000
●Every application runs on Linux in the context of a specific
user.
●Some applications may need higher privileges.
●Linux provides 3 special permissions:
○setuid
○setgid
○sticky bit
Special Permissions
●Used only for binary files (applications)
●Application with setuid bit set, runs with the effective UID
of the file owner
●Indicated by ‘s’ in place of ‘x’
●Set setuid bit
○Command: chmod u+s uidDemo
setuid
○If user doesn’t have execute ‘x’ permission, setting
setuid its represented by ‘S’ symbol
Remove setuid
○Command: chmod u-s uidDemo
●Used primarily for binary files (applications)
●File runs with permissions of group owning it.
●setgid is indicated by ‘s’ in place of ‘x’
●When applied on directories, files created are owned by
directory owner.
●Set setgid bit
○Command: chmod g+s uidDemo
setgid
Remove getuid
○Command: chmod g-s uidDemo
●If owner group doesn’t have execute ‘x’ permission it is
represented by ‘S’ symbol
●Used primarily on directories.
●When set, files created can only be deleted by user who
created it.
●Indicated by ‘t’ in place of ‘x’ in the everyone category.
●In RHEL, sticky bit is set by default on /tmp/
●Set sticky bit
○Command: chmod +t /documents
sticky bit
○If ‘others’ do not have execute permissions, it is
symbolized by ‘T’.
Remove sticky bit
○Command: chmod -t /documents
File Capabilities
●Grant specific privileges to executables, avoiding full root
permissions.
●Purpose:
○Precise control over access to system resources.
○Reduce need for processes to run with full root privileges.
●Example:
○Enable non-root processes to bind to port <1024 without
superuser privileges.
○Add ‘CAP_NET_BIND_SERVICE’ capability.
Common Capabilities
Set capability
○Command: setcap cap_net_raw /bin/ping
Get Capability
○Command: getcap /bin/ping
Get Capability of running process
○Command: getpcaps 1054