In Linux systems, the useradd
command is used to create new user accounts. One of the options available with this command is -c, --comment COMMENT
, which allows adding comments or remarks to provide additional information about the user being created.
When using the -c
option, you include a descriptive comment enclosed in quotes after the option. This comment is typically used to specify details such as the user’s full name, department, or any other relevant information.
Here are several examples demonstrating the usage of useradd
with the -c
option:
Example 1: Creating a user with a comment specifying the user’s full name:
useradd -c "John Doe" john_doe
This command creates a new user account named john_doe
and assigns the comment “John Doe” to it.
Verification: To verify if the command executed successfully, you can use the grep
command to check the contents of /etc/passwd
file:
grep john_doe /etc/passwd
Output (if successful):
john_doe:x:1001:1001:John Doe,,,:/home/john_doe:/bin/bash
Example 2: Adding a comment indicating the user’s department:
useradd -c "Jane Smith - HR Department" jane_smith
This command creates a user account named jane_smith
and includes the comment “Jane Smith – HR Department”.
Verification:
grep jane_smith /etc/passwd
Output (if successful):
jane_smith:x:1002:1002:Jane Smith - HR Department,,,:/home/jane_smith:/bin/bash
Example 3: Creating a user with a comment indicating special access permissions:
useradd -c "Service Account - Admin Access" svc_admin
This command creates a user account named svc_admin
with the comment “Service Account – Admin Access”, indicating administrative privileges.
Verification:
grep svc_admin /etc/passwd
Output (if successful):
svc_admin:x:1003:1003:Service Account - Admin Access,,,:/home/svc_admin:/bin/bash
Example 4: Adding a comment specifying a user’s role:
useradd -c "Developer Account" dev_user
This command creates a user account named dev_user
with the comment “Developer Account”.
Verification:
grep dev_user /etc/passwd
Output (if successful):
dev_user:x:1004:1004:Developer Account,,,:/home/dev_user:/bin/bash
Example 5: Including a comment to denote a project assignment:
useradd -c "Project X - Team Lead" team_lead
This command creates a user account named team_lead
with the comment “Project X – Team Lead”.
Verification:
grep team_lead /etc/passwd
Output (if successful):
team_lead:x:1005:1005:Project X - Team Lead,,,:/home/team_lead:/bin/bash
Example 6: Adding a comment indicating a user’s status:
useradd -c "Guest Account - Temporary Access" guest_user
This command creates a user account named guest_user
with the comment “Guest Account – Temporary Access”.
Verification:
grep guest_user /etc/passwd
Output (if successful):
guest_user:x:1006:1006:Guest Account - Temporary Access,,,:/home/guest_user:/bin/bash
Example 7: Specifying a user’s affiliation in a shared environment:
useradd -c "Consultant - External Services" consultant_user
This command creates a user account named consultant_user
with the comment “Consultant – External Services”.
Verification:
grep consultant_user /etc/passwd
Output (if successful):
consultant_user:x:1007:1007:Consultant - External Services,,,:/home/consultant_user:/bin/bash
Example 8: Adding a comment to describe a user’s specialization:
useradd -c "Researcher - AI & Machine Learning" researcher_ai
This command creates a user account named researcher_ai
with the comment “Researcher – AI & Machine Learning”.
Verification:
grep researcher_ai /etc/passwd
Output (if successful):
researcher_ai:x:1008:1008:Researcher - AI & Machine Learning,,,:/home/researcher_ai:/bin/bash
Example 9: Indicating a user’s primary responsibility:
useradd -c "Sysadmin - Infrastructure Management" sysadmin_user
This command creates a user account named sysadmin_user
with the comment “Sysadmin – Infrastructure Management”.
Verification:
grep sysadmin_user /etc/passwd
Output (if successful):
sysadmin_user:x:1009:1009:Sysadmin - Infrastructure Management,,,:/home/sysadmin_user:/bin/bash
Example 10: Adding a comment indicating a user’s role in compliance:
useradd -c "Auditor - Compliance Team" auditor_user
This command creates a user account named auditor_user
with the comment “Auditor – Compliance Team”.
Verification:
grep auditor_user /etc/passwd
Output (if successful):
auditor_user:x:1010:1010:Auditor - Compliance Team,,,:/home/auditor_user:/bin/bash
Discussion about this post