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
cp
,chmod
, andchown
? – John1024 May 17 '16 at 6:49