Adding user, changing home directory, adding to group

These are some Linux basics but are important to know and at some point, you’ll need them. Managing a Linux server or workstation even, you will have to create users, change passwords, create groups, add users to groups, and more. Today, I’m going to cover the top 4. Adding users, setting password, changing user home directory, and adding a user to an existing group.

Keep in mind, you have to be a sudo or root user to do this.

Adding user

Adding a user is very simple:

adduser newusername

Where it says “newusername” you can change that to anything you want to create the user name you want to create.

Setting user password

Setting the user password is easy as well. This can also be used to reset the password as well.

passwd newusername

As with the adding a user command, change the user name (newusername) to the user name you just set or to the username you want to change the password for. It will then ask you for the new password and to confirm it. After that, the password has been set.

Changing user home directory

We will be using the usermod command to change the user home directory. By default the user home directory is in the /home/ directory. If you created a user named, jsmith, their home directory would be /home/jsmith/. But lets say you created an FTP user or someone that needs access to a specific directory but not their default home directory, you would need to change their default home directory. This is especially useful for FTP user creation.

Here is how you change the default home directory for a linux user to something else:

usermod -d /var/www/html newusername

This is a simple switch of the default home directory for the username “newusername” to the /var/www/html directory. Of course you can change the directory and the username to anything you want to set their home directory.

Adding user to existing group

Finally, you will likely want to add a user to an existing group. This again is highly useful if you’re setting up an FTP user on a web server. You’d want to give them FTP group permissions along with your webserver permissions (typically apache or nginx) via their respective groups.

Here is how to add a user to an existing group:

usermod -a -G apache newusername

In the example above we are adding the user “newusername” to the apache group. Change the username and group to what you want it to be. Hit enter, and you will have successfully added that user to the group you specified.

Have an awesome Linux day!

Leave a Reply