The useradd
command in Linux is used to create new user accounts. One of the options available with this command is -o
or --non-unique
, which allows the creation of users with non-unique user IDs (UIDs).
When you use the -o
option with useradd
, it bypasses the usual check that prevents you from creating a user with a UID that already exists on the system. This can be useful in scenarios where you need to create multiple users with the same UID, typically for compatibility with certain applications or environments.
Here are some examples demonstrating the use of useradd -o
:
Example 1: Creating a new user with a non-unique UID:
sudo useradd -o john
This command creates a new user account named ‘john’, even if there is already another user with the same UID.
Example 2: Specifying a UID explicitly:
sudo useradd -o -u 1500 sarah
Here, the -u 1500
option sets the UID to 1500 for the new user ‘sarah’, bypassing the UID uniqueness check.
Example 3: Creating a system account with a duplicate UID:
sudo useradd -o -r -u 1001 appuser
This command creates a system account ‘appuser’ with UID 1001, ignoring any existing users with the same UID.
To verify if the useradd
command executed successfully, you can follow these steps:
- Check the existence of the newly created user by running
id username
, where ‘username’ is the name of the user you created. - Verify the UID assigned to the user matches the one specified in the command.
- Ensure there are no error messages indicating UID conflicts during the user creation process.
Discussion about this post