Since I'm working from home full time, I use my Ubuntu desktop PC for both work and personal stuff. To keep things neatly separated however, I have two different user accounts for that:
z1c0: The user account for my personal stuff.
work: Well, my work account.
Permission denied Problem
From time to time, however, I need to copy files from one account to the other, which usually goes like this:
Step 0: Permission denied
$ cp foo.png /home/z1c0/Pictures cp: cannot create regular file '/home/z1c0/Pictures/foo.png': Permission denied
Of course, you can
chown your way around this problem, but I was looking
for a permanent solution.
group to the rescue!
Whenever this problem came up, it involved sharing a file or folder somewhere in
~) folder. So this was where the solution needed to be applied.
To fix this once and for all, I decided to make one account's
and its contents recursively available to the other account and vice versa.
This is easily implemented using
Step 1: Create a new group
I created a new group named
sudo groupadd wolfgang
Step 2: Add the user accounts to the new group
z1co are added to the
sudo usermod -a -G wolfgang work sudo usermod -a -G wolfgang z1c0
Step 3: Log out and back in
Changes in group assignments only take effect when users log out and back in. Of course, you can also do this after the last step, but now is the best time.
Note: For some reason the last time I tried this, I even had to reboot my system until the group changes came into effect. Usually, logging out should be fine AFAIK though.
You can verify the changes by running the
groups command or listing the group members
for the new group.
$ getent group wolfgang wolfgang:x:1003:work,z1c0
Step 4: Assign files to the group
chgrp command we make all files and folders in the
home folder of
z1c0 account available to the
wolfgang group. Then we use the
command to give this group full
rwx (read, write, execute) rights.
sudo chgrp -R wolfgang /home/z1c0 sudo chmod -R 770 /home/z1c0
The we do the same thing for the
sudo chgrp -R wolfgang /home/work sudo chmod -R 770 /home/work
Step 5: Repeat Step 0
Now you should be able to
cp files and folders between these two user
accounts without any problem.
cp foo.png /home/z1c0/Pictures