HostOnNet Blog

useradd – create linux user

Looking for Linux Server Admin or WordPress Expert? We can help.

To create a user, run

useradd -d /home/USERNAME -s /bin/bash USERNAME

-d specify the home directory of the user.

-s specify the shell used by user.

Allow user to sudo

usermod -G sudo desktop

Create user with home directory

useradd -m USERNAME

Create a user with sudo rights

useradd -m -G sudo USERNAME

On RHEL/CentOS, replace sudo with wheel.

Create user with no SSH access

To create a linux user with no SSH/terminal access, run

useradd -s /sbin/nologin USERNAME

Create a User to run system service

Normally system services are run by users with UID/GID below 500. The -r flag of useradd will create user for system service. For example

groupadd -r prometheus
useradd -r -g prometheus -s /sbin/nologin -d /usr/hostonnet/prometheus/ -c "prometheus Daemons" prometheus

Set Password for a user

passwd USERNAME

Posted in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.