SlidePub
Home
Categories
Login
Register
Home
Design
A Complete Guide to “useradd” Command in Linux with Examples _ Hostbillo
A Complete Guide to “useradd” Command in Linux with Examples _ Hostbillo
KiyanaSharma1
53 views
12 slides
Jul 17, 2023
Slide
1
of 12
Previous
Next
1
2
3
4
5
6
7
8
9
10
11
12
About This Presentation
This article will cover how to use the useradd command in Linux to set up new user accounts.
Size:
373.42 KB
Language:
en
Added:
Jul 17, 2023
Slides:
12 pages
Slide Content
Slide 1
ACompleteGuideto“useradd”Commandin
LinuxwithExamples|Hostbillo
Introduction
MultipleuserscaninteractwithLinuxatoncebecauseitisamulti-usersystem.
Youareaccountableforoverseeingthesystem'susersandgroupsbyallowing
anddenyingusersandaddingandremovingthemfromdifferentgroups.
ThisarticlewillcoverhowtousetheuseraddcommandinLinuxtosetup
newuseraccounts.
UseaddCommand
FortheuseraddcommandinLinux,thefollowinggeneralsyntaxapplies:
useradd[OPTIONS]USERNAME
Slide 2
Userswithsudobenefitsorrootaretheonlyoneswhocancreatenewuser
accountsinLinuxusingtheuseraddcommand.
Accordingtothechoicesyoutypeatthecommandprompt,theuseradd
commandcreatesanewuseraccountonceyourunit.
Sincethevariablesinthisfilearedifferentbetweendistributions,theLinuxadd
usercommandbehavesdifferentlyonvarioussystems.
Additionally,useraddreadsthedatainthe/etc/login.defsfile.Thisfileincludes
configurationinformationfortheshadowpasswordsuite,includingpassword
expirationpolicy,userIDrangesusedwhencreatingthesystemandregular
users,andmore.
HowtoaddUserinLinux?
Usetheuseraddcommandafterenteringtheuser'snametocreateanewuser
inLinux.
Ifyouwantedtomakeanewuserwiththenameusername,youmightrun:
sudousername
Slide 3
Useraddusesthedefaultsettingslistedinthe/etc/default/useraddfilewhenitis
runwithoutanyoptions,creatinganewuseraccount.
Youneedtomarktheaccountpasswordpriortologgingintotherecently
createduserinlinux.Performthepasswdcommand,thenentertheusername:
sudopasswdusername.
Keepinmindtochooseanuniquepassword.
AddaNewUserandCreateaHomeDirectory
MostLinuxdistributionsdonotbuildtheuser'shomedirectorywhenevera
newlyaddedaccountissetupwithuseraddcommand.
Thehomedirectorywouldbecreatedbyimplementingthe-m(—create-home)
element.
Slide 4
sudouseradd-musername
Withtheaforementionedcommand,theuser'shomedirectoryiscreatedand
filesfromthe/etc/skeldirectoryarecopiedover.Youcanfindtheinitialization
filesbylistingthefilesinthe/home/usernamedirectory:
ls-la/home/username/
Auser'shomedirectorycancontainfoldersandfilesthattheycanadd,change,
anddelete.
CreateaUserwithSpecificHomeDirectory
UseraddCommandinLinuxinstantlycreatesthehomedirectory.Ifyouwantto
placetheuser'shomedirectorysomewhereelse,thenused(—home)feature.
Usingtheexamplebelow,youcanmakeanewuserwiththenameusername
andahomedirectoryof/opt/username:
Slide 5
sudouseradd-m-d/opt/usernameusername
CreateNewUserinLinuxwithSpecificUserId
UsernamesanduniqueUIDsareusedinLinuxandotherUnix-likeoperating
systemstoidentifyusers.
TheLinuxprogramgiveseachuseraspecialpositiveintegerthattheycanrefer
toastheir"useridentifier"(UID).TheUIDaswellasotheraccesscontrol
policiesdefinethetypesofactivitiesauserisallowedtoperformonsystem
resources.
ThesystemwillautomaticallydesignatethefollowingUIDfromthecatalogof
userIDsmentionedinthelogin.defsfiletoanewlycreateduserLinux.
Whenoperatinguseradd,utilise-u(—uid)optiontosetupauserwithanunique
UID.Forinstance,tocreateanewuserwiththeUIDof1700andthename
username,youwouldtype:
sudouseradd-u1700username
Withtheidcommand,youcanconfirmtheuser'sUID:
id-uusername
Slide 6
CreateaUserwithaSpecificGroupId
UseraccountsinLinuxareorganizedandmanagedbygroups,whichare
organizationalunits.Themainfunctionofgroupsistospecifyasetofprivileges
thatcanbesharedbyallmembersofthegroup,suchaspermissionsforreading,
writing,orimplementingaspecificresource.
Whenaddinganewuser,theuseraddpromptautomaticallycreatesagroupthat
hastheexactnameastheusernameandtheidenticalGIDastheUID.
Byusing-g(—gid)feature,youcanallocateausertoaspecificinitiallogin
group.YoucanchoosebetweenstatingthegroupnameandtheGIDnumber.
ThegroupIDornamemustalreadybeinuse.
Inthisexample,we'llcreateabrand-newuserwiththenameusername,and
we'llsetthelogingrouptousertype.
sudouseradd-gusersusername
Youcouldperhapsvalidatetheuser'sGIDbyusingidprompt:
id-gnusername
Slide 7
AddaUserandallotMultipleGroups
Theterms"primarygroup"aswellas"secondarygroup"refertotwodistinct
categoriesinLinuxoperatingsystems.Eachuserhasamaximumofone
primarygroupandzerotomoresecondarygroupstowhichtheycanbelong.
Withthe-G(—groups)option,youcanspecifyalistofextragroupsthatthe
userwillbelongto.
Withtheprimarygroupusers,secondarygroupswheel,anddocker,the
followingcommandcreatesanewuserwiththenameusername.
sudouseradd-gusers-Gwheel
Additionally,youcouldincorporatesearching
idusername
AddUserinLinuxwithoutanyHomeDirectory
Somesituationscallforustostepawayfromgivingusershomedirectoriesfor
safetypurposes.Inthiscase,theuser'shomedirectorywillberootwhenthey
logintoasystemthathasjustrestarted.Whensuchauserexecutesthesu
command,theprevioususer'shomedirectorywillbeusedasthelogindirectory.
Usingtheoption"-M,"userscanbecreatedwithouthavinghomedirectories.
Youcanmakeauserwithouttheneedforahomedirectorybyusingthe
commandprompt,forexample.
Slide 8
sudouseradd-Musername
Thelscommandwillnowbeusedtoconfirmthattheuserwasestablishedwith
noneedforahomedirectory.
sudols-l/home/username
ls:cannotaccess/home/username:Nosuchfileordirectory
AddNewUserwithExpiryDate
Youcandesignateadayandtimeforthenewlyaddedaccounts'expirationby
usingthe-e(—expiredate)feature.Thiscanbeusedtocreatetemporary
accounts.
Inordertospecifyadate,usetheformatYYYY-MM-DD.
Forinstance,tomakeanewuseraccountwiththenameusername(ABC)and
anexpirationdateofApril07th,2023,youwouldexecutethefollowing
command:
sudouseradd-e2023-04-07username(ABC)
Tofindoutwhenanaccountwillexpire,choosethechageprompt:
sudochage-lusername(ABC)
Slide 9
CreateNewUserwithCustomComments
Youcanprovideaprecisedescriptionforthenewuserbyusingthe-c
(—comment)option.Usually,acommentwillincludetheuser'sfullnameor
contactinformation.
Intheexamplebelow,weareaddinganewuserwiththenameusernameand
thecommenttextstringTestUserAccount:
sudouseradd-c"TestUserAccount"username
grepusername/etc/passwd
AnothernameforthecommentsectionisGECOS.
AddUserwithachangedloginshell
Slide 10
Theloginshellforanewuserisautomaticallysettotheonelistedinthe
/etc/default/useraddfile.Thedefaultshellsettingvariesbetweendistributions;
insome,itis/bin/sh,andinothers,/bin/bash.
Withthe-s(—shell)feature,youcanidentifythenewlyaddeduser'sloginshell.
Forexample,
sudouseradd-s/usr/bin/zshusername
Determinetheuser'sloginshellbyexaminingtheentryinthefile:
grepusername/etc/passwd
ThecommandforChangingtheDefaultuseraddValues
The-D,—defaultsfunction,allowsyoutoseeandmodifythestandarduseradd
configurations.
Toseethecurrentdefaultoptions,usethefollowingsyntax:
useradd-D
Considerthescenariowhereyouwanttoswitchfrom/bin/shto/bin/bashasthe
defaultloginshell.Enterthenewshellinthefollowingformattoachievethat:
sudouseradd-D-s/bin/bash
Slide 11
Userscanactuallyconfirmthatthestandardshellcomponenthasbeenaltered
byrunningthecommandshownbelow:
sudouseradd-D|grep-ishell
CommandtosetaPasswordforNewUser
Thefollowingcommandcanbeusedtosetanunencryptedpasswordforthe
user.
sudouseradd-ptest_passwordusername
Thiswillsetupanewuserwiththename"username"andtheunencrypted
password"testpassword".
CommandtoDisplayHelp
Youcandemonstratehelpbyenteringthefollowingsyntax.
sudouseradd--help
Theuseraddcommand'shelpsectionwillbedisplayedwhenthiscommandis
used.
Slide 12
Conclusion
We'vedemonstratedinthisarticlehowtousetheuseraddcommandinLinux
toaddnewuseraccounts.AllLinuxdistributions,suchasCentOS,RHEL,
Debian,Ubuntu,andothers,alsoshouldfollowthesameinstructions.Asof
rightnow,youcantestthesefeaturesandattempttogiveLunixmore
functionality.
Tags
Categories
Design
Download
Download Slideshow
Get the original presentation file
Quick Actions
Embed
Share
Save
Print
Full
Report
Statistics
Views
53
Slides
12
Age
869 days
Related Slideshows
1
MGV Residential Design projects for different clients, including a New Mexico Adobe project-1-.pdf
mannyvesa
26 views
16
EUNITED_Advocacy and Public Engagement through Visual Media
GeorgeDiamandis11
31 views
31
DESIGN THINKINGGG PPT 2 TOPIC IDEATION.pptx
HibaZaidi2
24 views
36
DESIGN THINKING CHAPTER 1 PPTT PPT 1.pptx
HibaZaidi2
28 views
112
Hinduism and Its History - PowerPoint Slides.pptx
ConorMcCormack10
24 views
20
Service Attributes of Manufactured Parts.pptx
MustafaEnesKrmac
24 views
View More in This Category
Embed Slideshow
Dimensions
Width (px)
Height (px)
Start Page
Which slide to start from (1-12)
Options
Auto-play slides
Show controls
Embed Code
Copy Code
Share Slideshow
Share on Social Media
Share on Facebook
Share on Twitter
Share on LinkedIn
Share via Email
Or copy link
Copy
Report Content
Reason for reporting
*
Select a reason...
Inappropriate content
Copyright violation
Spam or misleading
Offensive or hateful
Privacy violation
Other
Slide number
Leave blank if it applies to the entire slideshow
Additional details
*
Help us understand the problem better