- Ubuntu
- User Management
- here
useradd command-add user
You can add users using the useradd command.
You must have root privileges to add users. Let's work with root privileges using sudo. If you use sudo, you will be asked for the root password, so enter the root password.
Use the useradd command to add users. If you want to create a user directory, use the "-m" option.
First, create a user for running the web application with the name "myapp". This is intended for users running web applications and running batch programs in a production environment. Use the "-m" option to create a home directory, and the "-s" option to specify a shell. In Ubuntu, if nothing is specified, it will be "/ bin / sh", so leave it as "/ bin / bash".
#Add user (with home directory, use bash shell) sudo useradd -m myapp -s / bin / bash #Add user (no home directory) sudo useradd myapp
If you have a developer user, it's a good idea to create that user as well. The procedure, such as setting a password, is the same as for the myapp user.
#Add user (with home directory, use bash shell) sudo useradd -m kimoto -s / bin / bash
Password setting
After adding the user, set the password as well. Use the passwd command.
sudo passwd myapp
You will be asked to enter the password and re-enter it for confirmation, so set it.
Join sudo group
If you want to register this user as a sudo user with root privileges, add it to the sudo group using the gpasswd command.
sudo gpasswd -a myapp sudo
I added a user by mistake and want to delete it
If you accidentally added a user and want to remove it, use "userdel".
sudo userdel myapp
Rest assured that the contents of your home directory and emails will not be deleted.
If this user was using the process, it cannot be deleted.
You need to do it when the user isn't using the process, or check the process and kill it if it's okay to kill it.
#Check process ps -ef
Other user management operations
User deletion.
User list.
What to do if the useradd option is incorrect
If you forget to add the option "-m" in your home directory
Delete the user with userdel and create the user again with useradd.
sudo userdel myapp sudo useradd -m myapp -s / bin / bash
If you forget to add the default shell option "-s"
You can fix it with usermod.
sudo usermod -s / bin / bash myapp