0

I typically tend to log in as root, which I know is bad practice.

So I created another user, let's call it user1. Except now when I log in as that user I am placed in an empty /home directory and it is pretty useless.

The problem is I want user1 to have access to another users /home/ directory, effectively cloning the other users permissions. How can I do this?

2
  • Are you familiar with commands like cp, chmod, and chown? – John1024 May 17 '16 at 6:49
  • 1
    @John1024 yes I am, but last time I used them I ruined everything. – Chud37 May 17 '16 at 6:54
2

You could do that by having the same user id (UID) for both users, but it is a really bad practice and may have unintended consequences. See this for a comprehensive discussion about it.

A better way is either having those users in the same group and setting R or RW group permissions on their homes, or better still using extended attributes (man setfattr), or allowing your user to sudo su - <anotheruser> via /etc/sudoers file, or allowing your user to sudo to root.

Same group option

First create a special group, say team_a:

groupadd team_a

Then set that group to your users (say user1 and user2). By default each user is created in a new group with the same name as the user. You'll set team_a as the main group, and leave the individual groups as secondary groups:

for user in user1 user2; do usermod -g team_a $user; usermod -a -G $user $user; done

Then update permissions on user2's home, giving full access to any members of the team_a group, to the folder and any files and folders contained in it, recursively; this would allow any member of team_a accessing user2's home folder and files, but you're not granting access on any other users (e.g. the following doesn't provide access to members of team_a to your user1's home folder):

chmod -R g+rwX ~user2

Note that user2 could remove those permissions at any time, or create new files without granting access permissions to the group.

Finally, ensure that your other user(s) will create any files with full access for members of that group:

echo "umask 002" >> ~user2/.profile

Your user belonging to other users' default group:

Perhaps simpler than the above, you can add your user1 user to the default groups of any other users. By default in most Linux distros and UNIX systems, the default group permissions on new files is full access to the group when the user's group name is the same as the user's name, so there's no need to manipulate umask for those users in this case.

Setting user1 to belong also in user2's default group:

usermod -a -G user2 user1

Granting access access to members of user2 group to user2's home folder:

chmod g+rwX ~user2
4
  • Could you explain further the group permissions idea, with CLI examples please? :D – Chud37 May 17 '16 at 6:54
  • @Chud37 Added examples – Ezequiel Tolnay May 17 '16 at 7:06
  • @Chud37 Added another perhaps simpler option, plus a necessary extra requirement (umask) on the previous example – Ezequiel Tolnay May 17 '16 at 7:29
  • @ZiggyCrueltyfreeZeitgeister - You might want to change the first usermod command, so the new group is appended, to the user. You get rid of one line code by doing that. – Ramhound May 17 '16 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.