I want to create an user for my Tomcat installation, but I was viewing multiple options:
# groupadd tomcat # # useradd -g tomcat -d /usr/local/tomcat tomcat # useradd -g tomcat -c "Tomcat User" -d /usr/local/tomcat tomcat
# useradd -r -s /sbin/nologin tomcat # chown -R tomcat: /usr/local/tomcat
In other page (hidden and recursive)
# useradd -r tomcat --shell /bin/false # chown -hR tomcat: /usr/local/tomcat
# useradd -g tomcat -s /bin/bash -d /usr/local/tomcat tomcat # chown -Rf tomcat.tomcat /usr/local/tomcat
I don't know what is the mistake or consequence, I want to know what is the best option
I think is best to use -h hidden, but
chown - change file owner and group
-r, --system Create a system account. System users will be created with no aging information in /etc/shadow, and their numeric identifiers are chosen in the SYS_UID_MIN-SYS_UID_MAX range, defined in /etc/login.defs, instead of UID_MIN-UID_MAX (and their GID counterparts for the creation of groups). Note that useradd will not create a home directory for such an user, regardless of the default setting in /etc/login.defs (CREATE_HOME). You have to specify the -m options if you want a home directory for a system account to be created. -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.
In CentOS is needed to use -s or -r options?
# useradd -r UserL5C --shell /bin/false # more /etc/passwd | grep UserL5C UserL5C:x:494:491::/home/UserL5C:/bin/false # more /etc/group | grep UserL5C UserL5C:x:491: # finger UserL5C Login: UserL5C Name: Directory: /home/UserL5C Shell: /bin/false Never logged in. No mail. No Plan. #
UserL5C with UID and GID lower than 500
# useradd UserG5C --shell /bin/false # more /etc/passwd | grep UserG5C UserG5C:x:503:504::/home/UserG5C:/bin/false # more /etc/group | grep UserG5C UserG5C:x:504: # finger UserG5C Login: UserG5C Name: Directory: /home/UserG5C Shell: /bin/false Never logged in. No mail. No Plan. #
UserG5C UID and GID greater than 500
# ls -al /home/ total 32 drwxr-xr-x. 5 root root 4096 Jun 25 06:05 . dr-xr-xr-x. 25 root root 4096 Jun 25 05:19 .. drwx------. 33 IntUser IntUser 4096 Jun 25 05:46 IntUser drwx------. 2 root root 16384 Jun 13 09:56 lost+found drwx------. 4 UserG5C UserG5C 4096 Jun 25 06:01 UserG5C #
The difference UserG5C creates homeDirectory
It would be better to use: useradd UserG5C -M -s /bin/false because this user/account hasn't system privileges?