The Linux system provides a couple of command line utilities to create new users on the system
As we are aware, the Linux login has the essential fields listed as follows:
- A unique system wide username,
- A Strong password,
- The home directory and
- A login shell.
These are the mandatory fields to enable account creation.
The other fields are the UID and GID numbers associated with User an Group name numerical IDs which will be generated sequentially allocated by the Linux Kernel
We can do a broad categorization of login accounts into 2 types, those are the Privileged and the normal user.
The Absolute Privileged account is root which comes by default in all the linux machines.
The normal account can be enabled with root Privileged by assigning user to certain groups and providing elevated access in the scope.
What is the Process to create a User account in Linux?
The user creation has to be done with root privileges using useradd command.
$ sudo useradd newuser
Now it’s time to enter the password
$ sudo passwd newuser
How to check if the userid is present and active on the system?
The new user details will be updated to /etc/passwd file and the login information updated to /etc/shadow
Now let’s check if the user account is created and has a valid shell
vamshi@node03:/$ grep vamshi /etc/passwd vamshi:x:1001:1001::/home/vamshi:/bin/bash
How to Add the user to new groups in Linux?
Usermod command line linux utility enables to add user to groups and the ability to add an existing user to new groups additionally or overwrite the group membership
$ usermod -aG dockerroot wheel vamshi
-a: appends the user to two new groups called
wheel with out overwriting the existing user assigned groups, violating this option will restrict the newuser to be part of only the mentioned groups in the command
How to check and verify if the user is a member of group in Linux?
[vamshi@node02 Linux-blog]$ id vamshi uid=1001(vamshi) gid=1001(vamshi) groups=1001(vamshi),0(root),10(wheel),992(dockerroot)
How to Verify the Login Confirmation in Linux?
From the root user account run the command:
su - newuser to check the new login account environment.
How to find the group names assigned to the user
The user can list of his active membership groups by running the linux command
The user can run the groups command to list the groups with active membership
[vamshi@linuxcent ~]$ groups vamshi root wheel dockerroot
Login to the server remotely using SSH
You may now use the ssh command to login with the new username and enter your password at login prompt.
$ ssh email@example.com
How to connect to server with SSH running on non-standard port like
[vamshi@linuxcent ~]$ ssh localhost -p 2202 Last login: Mon Mar 13 17:57:56 2020 from 10.100.0.1
How to create a useraccount in Linux using useradd command?
The usercreation can also be done with parametrized command as demonstrated below:
$ sudo useradd vamshi -b /home/ -m -s /bin/bash
Alternatively you can be more elaborate as mentioned below:
$ sudo useradd vamshi -c "Vamshi's user account" -d /home/vamshi -m -s /bin/bash -G dockerroot
The useradd command-utility options describes as follows:
--base-dir : base directory of new user home directory.
--comment : Description about the user Or as A Standard Practice can be used to Mention the Current User’s Full name.
--home-dir : create the user’s home directory
--create-home : create the user’s home directory as per -d option.
--shell : Type of Login Shell.
--uid : is the Unique UID on linux machine
--groups : list of secondary groups to be assigned
--skel : determines the default parameters if no options are passed while account creation. Present at /etc/default/useradd
With the skel properties finely tunes, you can proceed to use
adduser command which is based on the default
skel behavior as shown below:
$ sudo adduser vamshi
How to using the SSH key pair to login:
-i followed by the /path/to/id_rsa private key file
$ ssh -i ~/.ssh/id_rsa firstname.lastname@example.org
$ ssh -i ~/.ssh/id_rsa -l linuxcent.com
-l: using the login name
-i : is the identity file; rsa the private key file
Troubleshooting the SSH connection in Verbose mode printing Debug information
-v option with the ssh command will print the debug information while logging
The verbosity levels
-v can be concatenated from one to Nine; eg
$ ssh -i ~/.ssh/id_rsa email@example.com -vvvvvvvvv