Oracle Enterprise Linux (OEL) is a popular Linux distribution optimized for running Oracle databases and applications. Proper user management is crucial for maintaining security and efficient system administration. In this post, we will cover how to create, modify, and manage users in Oracle Enterprise Linux.

1. Creating a New User

To add a new user, use the useradd command. The basic syntax is:

sudo useradd username
sudo useradd radu

For example, to create a user named oracleuser:

sudo useradd oracleuser
sudo useradd radu

Setting a Password for the User

After creating the user, set a password using the passwd command:

sudo passwd oracleuser

[opc@linus01 ~]$ sudo passwd radu
Changing password for user radu.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

You will be prompted to enter and confirm the password.

Specifying a Home Directory

By default, user home directories are created in /home/. You can specify a different directory with:

sudo useradd -d /opt/oraclehome oracleuser

[opc@linus01 ~]$ sudo ls -l /home/
total 0
drwx------. 6 opc  opc  177 Oct 19 11:22 opc
drwx------. 2 radu radu  76 Mar 10 20:47 radu

Assigning a Specific UID and GID

To create a user with a specific User ID (UID) and Group ID (GID):

sudo useradd -u 1200 -g 1001 oracleuser

2. Modifying an Existing User

If you need to modify an existing user, use the usermod command.

Changing the Username

sudo usermod -l newusername oldusername
[opc@linus01 ~]$ sudo usermod -l rparvu radu
sudo ls -l /home/
total 0
drwx------. 6 opc    opc  177 Oct 19 11:22 opc
drwx------. 2 rparvu radu  76 Mar 10 20:47 radu
su - rparvu
Password:
[rparvu@linus01 ~]$ pwd
/home/radu
...
[opc@linus01 ~]$ sudo usermod -l radu rparvu
[opc@linus01 ~]$ cat /etc/passwd | grep radu
radu:x:1001:1001::/home/radu:/bin/bash

Changing the User’s Home Directory

To move the home directory and update its contents:

sudo usermod -d /new/home/directory -m username

Adding the User to a Group

To add a user to an existing group:

sudo usermod -aG groupname username
[opc@linus01 ~]$
[opc@linus01 ~]$ sudo usermod -aG wheel radu
[opc@linus01 ~]$

For example, to add oracleuser to the dba group:

sudo usermod -aG dba oracleuser

3. Deleting a User

To remove a user while keeping their home directory:

sudo userdel username

To remove a user and their home directory:

sudo userdel -r username

4. Managing User Groups

Creating a New Group

sudo groupadd groupname

For example, to create a group named oraclegroup:

sudo groupadd oraclegroup

Adding a User to a Group

sudo usermod -aG oraclegroup oracleuser

Viewing Group Memberships

To see which groups a user belongs to:

groups oracleuser

5. Viewing and Managing Users

Listing All Users

To view all users on the system:

cat /etc/passwd

Checking User Details

To get information about a specific user:

id oracleuser

Viewing Currently Logged-in Users

who

or

w

6. Locking and Unlocking Users

To temporarily disable a user account:

sudo usermod -L username

To unlock the account:

sudo usermod -U username

[opc@linus01 ~]$ sudo usermod -L radu
[opc@linus01 ~]$ su - radu
Password:

su: Permission denied
[opc@linus01 ~]$
[opc@linus01 ~]$ sudo usermod -U radu
[opc@linus01 ~]$ su - radu
Password:
Last login: Mon Mar 10 20:53:25 GMT 2025 on pts/0
Last failed login: Mon Mar 10 21:01:16 GMT 2025 on pts/0
There was 1 failed login attempt since the last successful login.

7. SSH authentication from a Client machine

On the client machine, use ssh-keygen to generate a key if you do not have one:

ssh-keygen
Generating public/private ed25519 key pair.
Enter file in which to save the key (/Users/radu.parvu/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/radu.parvu/.ssh/id_ed25519
Your public key has been saved in /Users/radu.parvu/.ssh/id_ed25519.pub
The key fingerprint is:
...

On the server, navigate to the users .ssh directory and add the public part of the (generated) key to the authorized_keys file

echo "ssh-ed25519 public key content here" | sudo tee -a authorized_keys

Afterwards, you can use the SSH client of choice or a command like below to login:

ssh -i ~/.ssh/id_rsa newuser@oci-instance-ip

I use Royal TSX on macOS and is a lot of fun!

Conclusion

User management in Oracle Enterprise Linux is essential for maintaining a secure and efficient system. By using commands like useradd, usermod, userdel, and groupadd, administrators can create and maintain users effectively.

Would you like to see more automation scripts for user management? Let us know in the comments!


Discover more from Radu Pârvu

Subscribe to get the latest posts sent to your email.

Discover more from Radu Pârvu

Subscribe now to keep reading and get access to the full archive.

Continue reading

Join 1,647 other subscribers

Discover more from Radu Pârvu

Subscribe now to keep reading and get access to the full archive.

Continue reading