How to create restricted user in Linux


Restricted users are made to run only specific commands allowed by the administrator to execute in terminal. So in order to restrict user following is the procedure.

Step 1: Copy bash shell

Copy bash shell from /bin/bash and paste it as new restricted bash shell.

# cp /bin/bash /bin/rbash
# chmod o+x /bin/rbash

Step 2: Create rbash shell user

# useradd -s /bin/rbash testuser
# mkdir /home/testuser/commands
# passwd testuser
# chown testuser:testuser /home/testuser/commands/

Step 3: Assign specific commands

# cp /usr/bin/free /home/testuser/commands/
# cp /usr/bin/grep /home/testuser/commands/
# chmod 755 /home/testuser/commands/free
# chmod 755 /home/testuser/commands/top

Step 4: Update user profile

# cd ~testuser/
# vi .bash_profile

Leave a Reply

Notify of