Language: EN


Linux Commands - Permissions and Special Attributes

Here is a compilation of the most useful Linux commands on Permissions and Special Attributes

File and Folder Permissions

#use + to add permissions and - to remove
Show permissions.
ls -lh

#assign 0777 permissions to a file

#modify 0777 according to octal permission encoding
chmod 0777 file

#assign permissions to all files in a directory
chmod -R 0644 directory

#assign read (r), write (w), and execute (x) permissions to owner (u), group (g), and others (o) of a directory.

#use the necessary options to add or remove the desired permissions
chmod ugo+rwx directory

#change user of file
chown user file

#change user for all files in a directory
chown -R user directory

#change group of file
chgrp group file

#change user and group of file.
chown user:group file

SUID Permissions

#view all system files with configured SUID
find / -perm -u+s

#set SUID bit on binary file. The user running this file acquires the same privileges as the owner
chmod u+s /bin/file

#remove SUID bit on binary file
chmod u-s /bin/file

#set SGID bit on directory. Similar to SUID but for directories
chmod g+s /home/directory

#remove SUID bit on binary file.
chmod g-s /home/directory

#set a STIKY bit on a directory. Allows only legitimate owners to delete files
chmod o+t /home/directory

#remove STIKY bit on a directory.
chmod o-t /home/directory

Special File Attributes

#use + to add permissions and - to remove

#show special attributes.

#allows writing by opening a file in append mode only.
chattr +a file

#allows a file to be automatically compressed / uncompressed.
chattr +c file

#ensures that the program ignores deleting files during backup.
chattr +d file

#makes the file immutable, so it cannot be deleted, altered, renamed, or linked.
chattr +i file

#allows a file to be securely deleted.
chattr +s file

#ensures that a file is modified, changes are written in synchronous mode like with sync.
chattr +S file

#allows you to recover the content of a file even if it is canceled.
chattr +u file

To view the complete compilation of Linux commands follow this link: List of Linux commands