They are *overarching* groups, meaning they group other groups.
From a Linux standpoint they are no different from the normal groups, but we'll use the to group together the technical department and all users that don't need ssh.
Next we'll add the users and we'll set their passwords to a *test* password.
In order for them to share a `$HOME` directory we'll need to create one as well.
```bash
#!/bin/bash
# adding the groups
groupadd production
groupadd planning
groupadd script
groupadd technical
groupadd videoeditors
groupadd audioengineers
groupadd sftpjailed
# creating the shared home directory
mkdir -p /home/postproduction
# adding the users
useradd marie
echo "marie:test" | chpasswd
usermod -d /home/postproduction marie
useradd hugo
echo "hugo:test" | chpasswd
usermod -d /home/postproduction hugo
useradd victor
echo "victor:test" | chpasswd
usermod -d /home/postproduction victor
useradd camille
echo "camille:test" | chpasswd
usermod -d /home/postproduction camille
useradd dave
echo "dave:test" | chpasswd
usermod -d /home/postproduction dave
useradd sarah
echo "sarah:test" | chpasswd
usermod -d /home/postproduction sarah
useradd ester
echo "ester:test" | chpasswd
usermod -d /home/postproduction ester
useradd adam
echo "adam:test" | chpasswd
usermod -d /home/postproduction adam
useradd eefje
echo "eefje:test" | chpasswd
usermod -d /home/postproduction eefje
useradd alex
echo "alex:test" | chpasswd
usermod -d /home/postproduction alex
```
The quick ones among you probably see there is quite a lot of room for error here when typing the same names over and over again.
We can optimise this with some easy variables.
```bash
#!/bin/bash
# the shared home for all users
sharedhome="/home/postproduction"
mkdir -p $sharedhome
# adding the groups
groupadd production
groupadd planning
groupadd script
groupadd technical
groupadd videoeditors
groupadd audioengineers
groupadd sftpjailed
# adding the users
username="marie"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
username="victor"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
username="camille"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
username="dave"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
username="sarah"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
username="ester"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
username="adam"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
username="eefje"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
username="alex"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
```
Those who already did programming before see this is an ideal situation to create our own [functions](https://ryanstutorials.net/bash-scripting-tutorial/bash-functions.php).
Try to optimise the script if you can with your own function!
Next we need to add all the users to their groups.
```bash
#!/bin/bash
# the shared home for all users
sharedhome="/home/postproduction"
mkdir -p $sharedhome
# adding the groups
groupadd production
groupadd planning
groupadd script
groupadd technical
groupadd videoeditors
groupadd audioengineers
groupadd sftpjailed
# adding the users
username="marie"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
usermod -a -G production $username
usermod -a -G planning $username
usermod -a -G script $username
usermod -a -G technical $username
usermod -a -G videoeditors $username
usermod -a -G audioengineers $username
usermod -a -G sftpjailed $username
username="hugo"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
usermod -a -G production $username
usermod -a -G planning $username
usermod -a -G script $username
usermod -a -G sftpjailed $username
username="victor"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
usermod -a -G production $username
usermod -a -G planning $username
usermod -a -G sftpjailed $username
username="camille"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
usermod -a -G production $username
usermod -a -G planning $username
usermod -a -G sftpjailed $username
username="dave"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
usermod -a -G videoeditors $username
usermod -a -G technical $username
usermod -a -G sftpjailed $username
username="sarah"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
usermod -a -G videoeditors $username
usermod -a -G technical $username
usermod -a -G sftpjailed $username
username="ester"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
usermod -a -G videoeditors $username
usermod -a -G technical $username
usermod -a -G sftpjailed $username
username="adam"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
usermod -a -G audioengineers $username
usermod -a -G technical $username
usermod -a -G sftpjailed $username
username="eefje"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
usermod -a -G audioengineers $username
usermod -a -G technical $username
usermod -a -G sftpjailed $username
username="alex"
useradd $username
echo "$username:test" | chpasswd
usermod -d $sharedhome $username
usermod -a -G production $username
usermod -a -G planning $username
usermod -a -G script $username
usermod -a -G technical $username
usermod -a -G videoeditors $username
usermod -a -G audioengineers $username
```
When testing this out you'll quickly discover the need for a second script, one that removes all the users and groups from your system.
All of this serves to make a call to `$camille` and get `"production script sftpjailed"` in return so we can iterate over the groups.
There are *cleaner* ways of doing this and I would advise you to look into bash [arrays](https://www.gnu.org/software/bash/manual/html_node/Arrays.html).
If you decide to try this out, you *might* run into compatibility issues when testing in `zsh` but from inside a `bash` script you should be fine.
You can now log in with `filezilla` as any user of the film team and check if their permissions are correct.
Also try to log in with `ssh` and see if you can?
You should not be able to but we'll get to that in a minute.
I urge you to try it out and see think a bit about how you would improve it.
I can think of a few things.
* limit the group `sftpjailed` to only sftp and not ssh
* limit them to the project home directory so they can't walk around (and get lost) the entire file system
* when creating new files the entire owner and permission structure will become one gigantic mess!
We'll tackle all three problems one at a time.
### Limiting the group to sftp
This an `sshd` configuration setting so we'll need to edit the configuration file.
You should know *where* you can find it and if not *how* you can find out where is is located.
At the bottom of the file you'll see a *hint* towards adding rules from specific users and groups.
What would adding the following do you think?
```bash
Match Group sftpjailed
ForceCommand internal-sftp
```
Remember how to *apply* these changes to the `sshd` server?
Go ahead and restart it now.
Can you still log in over sftp?
What about ssh?
### Limiting the users to walk around the server
We can force users or groups to see a different *root* as lowest point of the directory tree.
With *root* I mean `/` and **not** the user `root`!
```bash
Match Group sftpjailed
ForceCommand internal-sftp
ChrootDirectory /home/postproduction
```
Relaunch the server and fire up a new connection.
Can you still walk around all over the server?
### Limiting the total mess new files will make
This a more tricky problem and it can be tackled in multiple ways.
Selçuk and Hugo solved it by using [acl](https://www.redhat.com/sysadmin/linux-access-control-lists) and I'll let them do a presentation on how to do it but I'm going old school with [setuid and setgid](https://en.wikipedia.org/wiki/Setuid) and [umasks](https://en.wikipedia.org/wiki/Umask).
I'll let you be the judge on which way is the easiest/best.
#### The last and final permissions
Those who did not just *copy/pasted* but read the file creation script must have noticed I set the permissions with four numbers instead of three!
The first number allows us to set the setuid and setgid values.
On directories it forces the ownership of newly created files and directories inside this directory to either the `user` or the `group` who owns said directory.
Sounds confusing?
Test it out on some throwaway directory you create in `/tmp` and you'll quickly see how it behaves.
On files it forces the file or script to be run as the owner or group.
This can be handy but also quite dangerous, especially on scripts.
Luckily Debian does [not allow](https://unix.stackexchange.com/questions/364/allow-setuid-on-shell-scripts) it's usage on scripts.
A bit more information for you reading pleasure can be found [here](https://www.techrepublic.com/blog/it-security/understand-the-setuid-and-setgid-permissions-to-improve-security/).
#### Permissions for new files
I invite you to create a throwaway directory somewhere in your own home directory.
Go into it and create a file.
What are the *standard* permissions this new files has?
Now ask yourself, where does this rule come from?
Enter the `umask`.
No, literally, try and see what happens when you enter the command `umask`.
These numbers are a *mask* that gets subtracted from fully open permissions.
For files they get subtracted form `666` and for folders from `777`.
Why would they need to be different for files and folders?
Knowing this, the umask you have is `022` and this get's subtracted from `666`, it makes sense the permissions for your newly created file are `644` no?
Try to change your umask and see how it behaves.
So with all of this in mind, how can we change the default umask for a user?
The solution is twofold.
For shell sessions such as `bash` or `zsh` we would do this in the `.profile` or `.zprofile` files but as most of our movie team users don't have shell access this won't be enough.
I'll leave you with [this](https://googlethatforyou.com?q=linux%20sftp%20set%20umask%20) to figure it out!