Sunteți pe pagina 1din 11

18/09/2015

HowToAddandDeleteUsersonUbuntu12.04andCentOS6|DigitalOcean

Community

By:EtelSverdlov

16

Menu

28

HowToAddandDeleteUsersonUbuntu12.04and
CentOS6

Jul27,2012

LinuxBasicsUbuntu,CentOS

WhattheRedMeans
Thelinesthattheuserneedstoenterorcustomizewillbeinredinthistutorial!Therest
shouldmostlybecopy-and-pastable.

Whenyoulogintoanewfreshlyspunupdroplet,youareaccessingitfromtherootuser.
Althoughthisgivesyouthepowertomakeanychangesyouneedontheserver,youare
muchbetteroffcreatinganothernewuserwithrootprivilegesonthevirtualprivateserver.
Additionally,ifotherpeoplewillbeaccessingthevirtualserver,youwillneedtomakenew
usersforthemaswell.Thistutorialwillgoovercreatinganewuser,grantingthemroot
privileges,anddeletingusers.

Whenyouperformanyroottaskswiththenewuser,youwillneedtousethephrase
sudobeforethecommand.Thisisahelpfulcommandfor2reasons:1)itpreventsthe
usermakinganysystem-destroyingmistakes2)itstoresallthecommandsrunwithsudo
toafilewherecanbereviewedlaterifneeded.Keepinmindhowever,thatthisuserisas
powerfulastherootuser.IfyouonlyneedauserforalimitednumberoftasksontheVPS,
youdonotneedtogivethemrootprivileges.

Setup
Thistutorialrequiresaccesstotherootuserorauserwithsudoprivileges.

Youshouldhavereceivedyourrootpasswordfromthewelcomeemailafteryoulaunched
yourdroplet.

https://www.digitalocean.com/community/tutorials/howtoaddanddeleteusersonubuntu1204andcentos6

1/11

18/09/2015

HowToAddandDeleteUsersonUbuntu12.04andCentOS6|DigitalOcean

UsersonUbuntu12.04

HowtoAddaUseronUbuntu12.04
ToaddanewuserinUbuntu,usetheaddusercommand,replacingthenewuserwith
yourpreferredusername.

sudoaddusernewuser

Assoonasyoutypethiscommand,Ubuntuwillautomaticallystarttheprocess:

Typeinandconfirmyourpassword

Enterintheusersinformation.Thisisnotrequired,pressingenterwill
automaticallyfillinthefieldwiththedefaultinformation

PressY(orenter)whenUbuntuasksyouiftheinformationiscorrect

Congratulationsyouhavejustaddedanewuser.Youcanlogoutoftherootuserby
typing

exit andthenloggingbackinwiththenewusernameandpassword.

HowtoGrantaUserRootPrivileges
Asmentionedearlier,youaremuchbetteroffusingauserwithrootprivileges.

Youcancreatethesudouserbyopeningthesudoersfilewiththiscommand:

nandopensourcetopics.

SignUp
sudo/usr/sbin/visudo

Addingtheusersnameandthesamepermissionsasrootunderthetheuserprivilege
SCROLLTOTOP

specificationwillgrantthemthesudoprivileges.

#Userprivilegespecification
rootALL=(ALL:ALL)ALL
newuserALL=(ALL:ALL)ALL

PresscntrlxtoexitthefileandthenYtosaveit.

https://www.digitalocean.com/community/tutorials/howtoaddanddeleteusersonubuntu1204andcentos6

2/11

18/09/2015

HowToAddandDeleteUsersonUbuntu12.04andCentOS6|DigitalOcean

HowtoDeleteaUser
Shouldyoufindthatyoufindthatyounolongerwanttohaveaspecificuseronthevirtual
privateserveryoucandeletethemwithasinglecommand.

sudouserdelnewuser

Finishupbythedeletingtheusershomedirectory:

sudormrf/home/newuser

UsersonCentOS6

HowtoAddaUseronCentOS6
ToaddanewuserinCentOS,usetheaddusercommand,replacingthenewuserwith
yourpreferredusername.

sudoaddusernewuser

Followupbyprovidingtheuserwithanewpassword,typingandconfirmingthenew
passwordwhenprompted:

sudopasswdnewuser

Congratulationsyouhavejustaddedanewuserandtheirpassword.Youcanlogoutof
therootuserbytyping

exit andthenloggingbackinwiththenewusernameand

password.

HowtoGrantaUserRootPrivileges
Asmentionedearlier,youaremuchbetteroffusingauserwithrootprivileges.

Youcancreatethesudouserbyopeningthesudoersfilewiththiscommand:

sudo/usr/sbin/visudo
https://www.digitalocean.com/community/tutorials/howtoaddanddeleteusersonubuntu1204andcentos6

3/11

18/09/2015

HowToAddandDeleteUsersonUbuntu12.04andCentOS6|DigitalOcean

Youwillfindthesectiontomaketheuserprivilegemodificationsatthebottomofthefile.
Typeatostartinsertingtext.Addingtheusersnameandthesamepermissionsasroot
underthetheuserprivilegespecificationwillgrantthemthesudoprivileges.

##Allowroottorunanycommandsanywhere
rootALL=(ALL)ALL
newuserALL=(ALL)ALL

SaveandExitthefilebypressshiftZZ.

HowtoDeleteaUser
Shouldyoufindthatyoufindthatyounolongerwanttohaveaspecificuseronthevirtual
privateserveryoucandeletethemwithasinglecommand.

sudouserdelnewuser

Youcanaddtheflag-rtothecommandifyouwouldliketosimultaneouslyremovethe
usersshomedirectoryandfiles.

sudouserdelrnewuser

NextSteps
Onceyouhavesetuptheuserswillyouneed,youcanstartbuildingupyourVPS.Agood
placetostartistoinstalltheLAMPstack(acollectionofbasicwebserversoftware)on
yourdroplet,usingthetutorialsbelow.

LAMPonUbuntu12.04

LAMPonCentOS6

LEMPonUbuntu12.04

LEMPonCentOS6

https://www.digitalocean.com/community/tutorials/howtoaddanddeleteusersonubuntu1204andcentos6

4/11

18/09/2015

HowToAddandDeleteUsersonUbuntu12.04andCentOS6|DigitalOcean
ByEtelSverdlov

Heart

16

Share

Subscribe

Author:
EtelSverdlov

SpinupanSSDcloudserverinunderaminute.
Simplesetup.Fullrootaccess.
Straightforwardpricing.

DEPLOYSERVER

RelatedTutorials
AnIntroductiontoLinuxPermissions

HowToDownloadSoftwareandContentontoyourLinuxVPS

AnIntroductiontoUsefulBashAliasesandFunctions

AnIntroductionToRegularExpressions

HowToUseBashHistoryCommandsandExpansionsonaLinuxVPS

https://www.digitalocean.com/community/tutorials/howtoaddanddeleteusersonubuntu1204andcentos6

5/11

18/09/2015

HowToAddandDeleteUsersonUbuntu12.04andCentOS6|DigitalOcean

28Comments

Leaveacomment...

LogIntoComment

danafrancey February8,2013

TheinstructionsforcentOS6arewrong.Ineededtouse:"passwd"insteadof"sudo
passwd"pertheguide.

chris81127 February10,2013

OnCentos,workedasexpected.Thanks.Quickquestion.

SometimesIliketoSFTPintotheserverandaddafolderorafile.Forinstance,into
/etc/nginxdirtoaddsitestosites-enabled.TheproblemIamrunningintoisthatthis
newuserdoesnothavetherightstoaddafileinto/etc/nginx,Igetapermissionerror.I
couldsshinandsu,thenaddthefilesasroot,butIamtryingtocomeupwithasolution
thatisbothsecureandallowsforeasierinteractionviaSFTPwhenIaminthemoodfor
that.

Anysuggestions?Iimaginesomesortofchownandchmodmightbeinorder.

chris81127 February11,2013

...here'swhatIdidtomakeworkingviathecommandlineandviaSFTPabiteasier
withinthewebrootandvariousconfigdirectories.

chown-Rusername:nginx/srv

https://www.digitalocean.com/community/tutorials/howtoaddanddeleteusersonubuntu1204andcentos6

6/11

18/09/2015

HowToAddandDeleteUsersonUbuntu12.04andCentOS6|DigitalOcean

chown-Rusername:nginx/etc/nginx

Seemstobeworking.

koro76 March5,2013

ItriedyourinstructionsforUbuntu12.04tonoavail.Creatingtheuserworkedfine,but
yourinstructionsforgivingtheuserrootpermissionsdidnotwork.

PaulW2U April28,2013

OnUbuntu12.10Ineededtoalsodo

addusersudo

toenablesudoaccesstomynewusername

bardi_e May2,2013

Onubuntu12.04asrootIsimplydid:

sudoadduserbardi
sudoadduserbardisudo

Veryeasyifyouknowhow!
1

prasenjit.haty June9,2013

Hi,

PleasefixthesyntaxforsettingpasswordfornewuserinCentOS.Itissupposedtobe

sudopasswdnewuser

kamaln7 June10,2013

@PrasenjitThanks,updated.

https://www.digitalocean.com/community/tutorials/howtoaddanddeleteusersonubuntu1204andcentos6

7/11

18/09/2015

HowToAddandDeleteUsersonUbuntu12.04andCentOS6|DigitalOcean

oscar June24,2013

OnUbuntutogetsudoaccessallyouneedtodoisaddtheusertothesudogroup
whichcansimplybedonebytyping:
sudoaddusernewuser
sudoaddusernewusersudo

Youdon'thavetomanuallyeditthesudoersfile.

dborchert August6,2013

IdidthisnowIcannotgetbackintothe/usr/sbin/visudoarea.Itsays:

sudo:>>>/etc/sudoers:syntaxerrornearline19

kamaln7 August7,2013

@dborchert:Didyouedit/etc/sudoersmanually?

dborchert August8,2013

Idid.OnlybecauseintheGUI,whenIwenttoUserAccounts,Icouldn'taddanything.It
keptsayingtoclicktheUnlockiconbutnotmatterwhatIdoIcan'tclickit--almostlike
it'sjustanimage,notabutton.

dborchert August8,2013

Kamal,fixedit.http://askubuntu.com/questions/209558/broken-sudo-sudo-parse-errorin-etc-sudoers-near-line-23

blu3 September18,2013

IhadthesameproblemaschrisaboveinwantingtouploadfromanewuserviaSFTP
butgettingpermissiondenied.

IfollowedhisguidelinesandsetthisonUbuntu:

chown-Rusername/var/www

Thisgivesmeprivilegestouploadtoanyofmydomainsthroughmynewuser.But-it
doesn'tfeellikethat'sthecorrectwayofdoingit?

https://www.digitalocean.com/community/tutorials/howtoaddanddeleteusersonubuntu1204andcentos6

8/11

18/09/2015

HowToAddandDeleteUsersonUbuntu12.04andCentOS6|DigitalOcean

Cananyonetellmeofabettersolution?

kamaln7 September18,2013

@crispyO:Ifyouwanttoshareacertaindomain'sfileswithtwousers,youhavetocreate
a'developers'(itcouldbenamedanythingyouwant)group(

groupadddevelopers

)andaddbothuserstothatgroup(

usermodaGdevelopersuser1#sameforuser2

).

Onceyou'vedonethat,youshouldchangethesite'sfile'sgroupto'developers'andadd
groupwritepermissions:

sudochgrpRdevelopers/var/www/domain.com
sudochmodRg+w/var/www/domain.com

Ialsorecommendsettingthesetgidbitsothatanynewfile'sgroupisautomaticallyset
todevelopers:

sudochmodRg+s/var/www/domain.com

ethan September27,2013

WhatifIwanttocreateauserthat*doesn't*haverootprivileges?WhatifIwantto
restrictacertainusertoaspecificfolder?

kamaln7 September28,2013

@ethan:

https://www.digitalocean.com/community/tutorials/howtoaddanddeleteusersonubuntu1204andcentos6

9/11

18/09/2015

HowToAddandDeleteUsersonUbuntu12.04andCentOS6|DigitalOcean

sudoaddusernewuser

shouldcreateanewuserwithoutroot/sudoprivileges.

pablo December4,2013

Suggestion:WhateverhappenedtoAmericabeingthelandofequalopportunity?How

'boutaddinglinkstoDigitalOcean'sLEMPstackarticlesintheNextStepssection?

kamaln7 December4,2013

Pablo,IbelievetheLEMParticlesdidn'texistwhenthisonewaswritten.I'lladdthem,
thanks:]

jeanbaptisteweber March8,2014

Ican'tusemykeyboard.Ican't=or:....

LoadMoreComments

ThisworkislicensedunderaCreative
CommonsAttribution-NonCommercialShareAlike4.0InternationalLicense.

https://www.digitalocean.com/community/tutorials/howtoaddanddeleteusersonubuntu1204andcentos6

10/11

18/09/2015

HowToAddandDeleteUsersonUbuntu12.04andCentOS6|DigitalOcean
Copyright2015DigitalOceanInc.

Community

Tutorials

Terms,Privacy,&Copyright

Questions

Security

Projects

Tags

ReportaBug

RSS

GetPaidtoWrite

https://www.digitalocean.com/community/tutorials/howtoaddanddeleteusersonubuntu1204andcentos6

11/11

S-ar putea să vă placă și