$ ls -l<\/code><\/pre>\n\n\n\nYou’ll see an output similar to the following:<\/p>\n\n\n\n
-rw-r--r-- 1 user group 1234 Oct 1 12:34 myfile.txt drwxr-xr-x 2 user group 4096 Oct 1 12:34 mydirectory<\/code><\/p>\n\n\n\nThe permissions are represented by the first set of characters (-rw-r--r--<\/code> or drwxr-xr-x<\/code>). In this example, the first file has read (r<\/code>) and write (w<\/code>) permissions for the owner but only read (r<\/code>) permission for the group and others. The second item is a directory (d<\/code>) with the execute (x<\/code>) permission for the owner, but only read (r<\/code>) permission for the group and others.<\/p>\n\n\n\nChanging Permissions<\/strong><\/h2>\n\n\n\n1. Using chmod<\/code> Command<\/strong><\/h3>\n\n\n\nThe chmod<\/code> command allows you to change file and directory permissions. Here’s a basic syntax for changing permissions:<\/p>\n\n\n\n$ chmod who=permissions file_or_directory<\/code><\/pre>\n\n\n\n\nwho<\/code> can be a combination of:\n\nu<\/code>: Owner<\/li>\n\n\n\ng<\/code>: Group<\/li>\n\n\n\no<\/code>: Others<\/li>\n\n\n\na<\/code>: All (equivalent to ugo<\/code>)<\/li>\n<\/ul>\n<\/li>\n\n\n\npermissions<\/code> is a combination of:\n\nr<\/code>: Read<\/li>\n\n\n\nw<\/code>: Write<\/li>\n\n\n\nx<\/code>: Execute<\/li>\n\n\n\n-<\/code>: Remove the permission<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\nFor example, to add execute permission for the owner and group on a file, you can use:<\/p>\n\n\n\n
$ chmod u+x,g+x file<\/code><\/pre>\n\n\n\n2. Using Numeric Mode<\/strong><\/h3>\n\n\n\nYou can also use numeric values to represent permissions. Each permission is assigned a numeric value: 4<\/code> for read, 2<\/code> for write, and 1<\/code> for execute. To set permissions, you sum these values:<\/p>\n\n\n\n\nRead (4) + Write (2) + Execute (1) = 7<\/li>\n<\/ul>\n\n\n\nFor example, to grant read, write, and execute permissions for the owner and group while allowing only read for others, use:<\/p>\n\n\n\n
$ chmod 770 file<\/code><\/pre>\n\n\n\nChanging Ownership<\/strong><\/h2>\n\n\n\nYou can change the owner and group of a file or directory using the chown<\/code> and chgrp<\/code> commands, respectively.<\/p>\n\n\n\nFor example, to change the owner of a file:<\/p>\n\n\n\n
$ sudo chown new_owner file<\/code><\/pre>\n\n\n\nTo change the group of a file:<\/p>\n\n\n\n
$ sudo chgrp new_group file<\/code><\/pre>\n\n\n\nConclusion<\/strong><\/h2>\n\n\n\nUnderstanding and managing file and directory permissions in Ubuntu Server is essential for maintaining a secure and organized system. By using the chmod<\/code> command and understanding the numeric mode, you can effectively control access to your files and directories. Be mindful of the permissions you assign to ensure the integrity and security of your server.<\/p>\n","protected":false},"excerpt":{"rendered":"Managing file and directory permissions is crucial for maintaining a secure and organized Ubuntu Server. In Ubuntu, permissions define who can access, modify, or execute files and directories. In this…<\/p>\n","protected":false},"author":1,"featured_media":13782,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,9,16],"tags":[193,354,424,433,544,572,573,591,598],"yoast_head":"\n
Set Permissions on Files and Directories in Ubuntu Server 22.04<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n \n \n \n \n \n\t \n\t \n\t \n