ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Operating Systems

How to Manipulate Ubuntu User Accounts and Groups Using Terminal

Updated on March 26, 2016

Before Everything Else!

Before we get to the chase, there are a few steps to make:

1. Boot up your computer.

2. Log in to your User Account (make sure you are not logged in as Guest).

3. Open the Dash by clicking the Ubuntu icon in the upper-left corner of the screen, type "Terminal", and select the Terminal application from the results that appear.

or

Hit the keyboard shortcut Ctrl+Alt+T.

4. Click the Terminal icon.

A step-by-step procedure before playing with the Terminal.
A step-by-step procedure before playing with the Terminal.

What are User Accounts and Groups?

Linux uses groups for organizing users. Groups are collections of user accounts with the same permissions and/or settings.

Management of group membership is administered through the /etc/group file, which shows a list of groups and their members.

The management of Groups can also be accomplished through the use of Terminal, which is what I'll be teaching you.

By default, every user belongs to a default or primary group. When a user logs in, the group membership is set for their primary group and all the members enjoy the same level of access and privilege. Permissions on various files and directories can be modified at the group level.

Groups are used to establish a set of users who have common interests for the purposes of access rights, privileges, and security considerations. Access rights to files (and devices) are granted on the basis of the user and the group they belong to.


Who Are You?

There is a Terminal command in Ubuntu that let's you check the account you are currently logged in to. This is important as you would want to avoid errors in the configuration of Users and Groups.

1. To check the User Account you are currently logged in with the Ubuntu Terminal, use the command: "whoami".

$ whoami


2. To know which other User Account are currently logged in, in the PC you are working on, type:"who".

$ who

3. To see a more detailed result in the "who" command, try putting "-a" after it.

$ who -a
 

Click the image to enlarge
Click the image to enlarge

Adding User Accounts

1. To add users with the UbuntuTerminal, you have to use the command: "useradd".

$ sudo useradd <any desired name>


2. To add password to the recently added Account, use the following command:

$ sudo passwd <user account you wish to add a password to>


  • Note that upon pressing enter, the Terminal will then let you assign a password to the User Account you just made.
  • While you are typing in the password, you will see that no characters nor asterisks will show up as you are typing in the password. Don't worry. That is normal.


Deleting User Accounts

To delete a User Account in Ubuntu, that User Account has to exist first. That is, if you want to delete one, make sure you made it before, or else you will get an error.

1. Deleting a User Account is fairly simple. The right command for this task is, you've guessed it, "userdel".

$ sudo userdel <user account you wish to delete>


  • Please note that, if you ever attempt it, deleting the administrator account is not possible.


Adding a Group

A Group in Ubuntu is a a collection of User Accounts. Group is made to ease the management of related User Accounts.

For example, a Group named STUDENT can be created to manage every single User Account of pupils in a class.

1. To add a Group, we use the command "groupadd".

$ sudo groupadd <desired name for a group>


  • The word sudo before the command groupadd is used to denote that you are issuing this command as the Administrator.


Deleting a Group

Deleting a group is just as easy as creating one.

1. To remove a group, you need to type in: "groupdel".

$ sudo groupdel <group name you wish to delete>



How to Add an EXISTING User Account to an Existing Group Account

1. To add a User Account to a particular Group, type this:

$ sudo adduser <name of the existing user account> <the group name>


  • Before doing this, make sure that both the User Account and the Group have already been made.


How to Add a NEW User Account to an Existing Group Account

1. To add a new User Account to a particular Group, type this:

$ sudo adduser <name of the new user account> <the group name>


  • Before doing this, make sure that the Group you wish the new User Account to be a member of has already been made.
  • Make sure to put a password to the recently-added user if you need to.


How to Remove a User Account from a Group

What if you made a your student's User Account a member of the FACULTY group. How do you remove him from there? Here's how.

1. To delete a User Account's membership to a particular Group, use this command.

$ deluser <user account you wish to remove> <group name to which that user is a member of>


  • Before doing this, make sure that the Group you wish the new User Account to be a member of has already been made.
  • Take note that only the membership is what you are deleting, not the User Account itself. If you want to delete the Account itself, you have to use the userdel command.


Summary of Commands (A)

 
AddUser Account
Group
Add
sudo useradd <a>
sudo groupadd <a>
Delete
sudo userdel <a>
sudo groupdel <a>
Fairly easy to memorize, huh?

Summary of Commands (B)

 
With an Existing User
With a New User
Add a User to a Group
sudo adduser <a> <b>
sudo adduser <a> <b>
Remove a User from a Group
sudo deluser <a> <b>
N.A.
 
 
 
You need to refer to the whole article for the complete commands.

Other Things...

"sudo":

  • sudo is a command that denotes the use of Administrative privileges.

"Case Sensitvity":

  • Ubuntu is always case sensitive, even with names, so make sure you type carefully.

"Ctrl + C":

  • press this keyboard combination to stop the process of a command that won't end!

"$":

  • This dollar sign you see before the commands is not actually included in the command itself, this was just used in the article to show that you are typing and accessing the Terminal in the unprivileged mode.

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.