I want to be able to log in with different settings but still be the same "user". So, I added a 2nd user with the same UID/GUID but different home directory and now when booting Ubuntu the system just hangs. If I remove the 2nd user from the passwd
and shadow
files, the system boots just fine.

- 33,355
- 17
- 105
- 120

- 285
-
2So you just learned you can't do that. If you want different settings then create different users. – Dec 02 '17 at 02:56
-
- I want to know why, what's broken so that I can't do that. I used to do that all the time. I can then fix the broken thing.
– intel_chris Dec 02 '17 at 07:59 -
- I want the second copy to have the exact same file access as the first. Think of it like development and stable branches. I work in the development user most of the time, when I am satisfied that I haven't broken my environment, I copy (using git) over to the stable user. However, if I break the environment, I simply switch to the stable user and haven't lost a thing. I do the same thing with entire versions of ubuntu, 2 partitions per drive, 2 hard drives per laptop, 2 laptops
– intel_chris Dec 02 '17 at 08:14
1 Answers
It is normally bad idea to edit the /etc/passwd
and the /etc/shadow
file by hand. I recommend using the system given tools for that. Beside that, while you can have a user share the same GUID with another user, the UID has to be unique for each user. So the boot will most likely fail to either Linux preventing the start of necessary applications and/or to failure of applications expecting the UIDs to be unique.
A better approach of two users sharing a directory is using group management to do that. See the Documentation about user management or browse Ask Ubuntu for possible guides:
However you can create a user by simply issuing the following command:
sudo useradd -U -m -G <additional groups here> <user-name>
This will add a user to your system which will work. Explanation of the above line from man 8 useradd
(extremely shortened to only the most usual options, for complete overview view the man page):
OPTIONS
The options which apply to the useradd command are: -c, --comment COMMENT Any text string. It is generally a short description of the login, and is currently used as the field for the user's full name. -g, --gid GROUP The group name or number of the user's initial login group. The group name must exist. A group number must refer to an already existing group. If not specified, the behavior of useradd will depend on the USERGROUPS_ENAB variable in /etc/login.defs. If this variable is set to yes (or -U/--user-group is specified on the command line), a group will be created for the user, with the same name as her loginname. If the variable is set to no (or -N/--no-user-group is specified on the command line), useradd will set the primary group of the new user to the value specified by the GROUP variable in /etc/default/useradd, or 100 by default. -G, --groups GROUP1[,GROUP2,...[,GROUPN]]] A list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace. The groups are subject to the same restrictions as the group given with the -g option. The default is for the user to belong only to the initial group. -k, --skel SKEL_DIR The skeleton directory, which contains files and directories to be copied in the user's home directory, when the home directory is created by useradd. This option is only valid if the -m (or --create-home) option is specified. If this option is not set, the skeleton directory is defined by the SKEL variable in /etc/default/useradd or, by default, /etc/skel. If possible, the ACLs and extended attributes are copied. -m, --create-home Create the user's home directory if it does not exist. The files and directories contained in the skeleton directory (which can be defined with the -k option) will be copied to the home directory. By default, if this option is not specified and CREATE_HOME is not enabled, no home directories are created. -M Do no create the user's home directory, even if the system wide setting from /etc/login.defs (CREATE_HOME) is set to yes. -s, --shell SHELL The name of the user's login shell. The default is to leave this field blank, which causes the system to select the default login shell specified by the SHELL variable in /etc/default/useradd, or an empty string by default. -U, --user-group Create a group with the same name as the user, and add the user to this group. The default behavior (if the -g, -N, and -U options are not specified) is defined by the USERGROUPS_ENAB variable in /etc/login.defs.
So -U
will create a user-group similar named to the user-name having the GUID match the users UID. -m
will create the users home directory in /home/<user-name>
and -G
lets you give additional groups to which this user should belong to. You can add groups later on too. The groups Ubuntu adds to the main user are adm
, cdrom
, sudo
, dip
, plugdev
, lpadmin
and sambashare
. To add groups later on you can use the following command:
sudo usermod -aG <group-or groups> <user-name>
Finally your user should have a password which you can set with:
sudo passwd <username>
This concludes the user creation process in a terminal.
There is a combined command available too called adduser
which automates some of the process you seen mentioned above, for its usage have a look at man 8 adduser
.

- 33,355
- 17
- 105
- 120
-
I used the adduser command to add the second user, simply specifying the --uid 1000 option to reuse the same uid. Yes, I removed the by editing the files by hand, but that's because I had to use my other copy of ubuntu on the system to edit the files, since the modified copy wouldn't boot. – intel_chris Dec 02 '17 at 07:53
-
Well, at least now you know why. You can have a read into how
chroot
works, this would have alowed you to handle the users on a normal way :) – Videonauth Dec 02 '17 at 07:55 -
No, I don't know why. I still just know that something hangs. I don't know what fails. Also, I don't see how chroot would solve my problem. I still wouldn't have two environments which share all the files. As far as I recall chroot, helps make a restricted environment that sees only a subset of the system, like if you want a restricted anonymous ftp. – intel_chris Dec 02 '17 at 10:09
-
You could have used chroot to mount into your broken system from an USB stick and do your fixes this way with normal command line tools. And you should definitively read into user management. Having two names of different users share the same UID is simply always a call for trouble and should be avoided. – Videonauth Dec 02 '17 at 10:16
-
ok I understand what you are suggesting with chroot. I can do that from my other ubuntu partitition. (I don't have a usb stick.) – intel_chris Dec 02 '17 at 10:24
-
and where do you recommend I read about user management, as a topic. – intel_chris Dec 02 '17 at 10:27
-
Her a comprehensive answer how to mount into chroot, see the footnotes so you dont miss a step: https://askubuntu.com/a/980270. And in this answer here i gave a good list as starting point to user management: https://askubuntu.com/a/981814 – Videonauth Dec 02 '17 at 10:32
-
I would suggest two really different users and them using group membership to access the different or same directory. – Videonauth Dec 02 '17 at 10:33
-
-
1"the UID has to be unique for each user": no, see https://askubuntu.com/a/427257/340225 – Clément Nov 11 '22 at 01:14