Linux Shell FAQs
Once you have accessed Polaris through SSH, you will be in a Linux Bash shell. This will not be a comprehensive guide, but instead will give a general overview of our most frequently asked questions.
Linux File Permissions
A good overview of Linux file permissions can be found here, but a brief overview is that permissions are tiered into User, Group, and Other. Each tier has three permissions that can be enabled or disabled; Read (r), Write (w), and Execute (x).
To find a file's permissions, use the ls -l
command.
[picardjl@polaris:~]$ ls -l prime-directive.txt
-rw-rw----. 1 picardjl picardjl 0 Dec 9 10:47 prime-directive.txt
In this case, the file prime-directive.txt
has Read and Write permissions for the User picardjl, Read and Write for the Group picardjl, and no permissions for anyone else.
In order to change permissions, we need to use the chmod
command. Let's say we want everyone to be able to read this file. We would nead to add the 'Read' bit to 'Other' in the file's permissions.
[picardjl@polaris:~]$ chmod o+r prime-directive.txt
[picardjl@polaris:~]$ ls -l prime-directive.txt
-rw-rw-r--. 1 picardjl picardjl 0 Dec 9 10:47 prime-directive.txt
Our file now has the Read (r) bit set.
Another method would be to use o=
and supply our mask. Let's say we want to remove all ability to edit this document from Group (g) and Other (o).
[picardjl@polaris:~]$ chmod g=r,o=r prime-directive.txt
[picardjl@polaris:~]$ ls -l prime-directive.txt
-rw-r--r--. 1 picardjl picardjl 0 Dec 9 10:47 prime-directive.txt
Let's move this document into a folder of other public documents we also want everyone to have access to. One quirk of the Linux file structure is that, in order to move through a directory, you don't use Read (r) permissions, you use Execute (x). Therefore, if we want people to have access to this directory (Execute) AND list all the files inside (Read), we need to grant them Read (r) and Execute (x) permissions. ls -ld
will show the permissions of a directory.
[picardjl@polaris:~]$ mkdir federation_docs
[picardjl@polaris:~]$ mv prime-directive.txt federation_docs/
[picardjl@polaris:~]$ ls -ld federation_docs/
drwxrwx---. 2 picardjl picardjl 33 Dec 9 10:59 federation_docs/
[picardjl@polaris:~]$ chmod o+rx federation_docs/
[picardjl@polaris:~]$ ls -ld federation_docs/
drwxrwxr-x. 2 picardjl picardjl 33 Dec 9 10:59 federation_docs/
For a more comprehensive guide to the chmod command, please see this HowToGeek article.