Linux Create Users : How To Create Users In Linux

Blogs ❯❯ Linux

Image could not load

Image by pixabay

जैसा कि हम जानते हैं कि Linux एक multi-user system है जिसका मतलब है same time पर एक से ज्यादा users same system से interact कर सकते हैं। As a system administrator, system’s users और groups को create / remove या users को different groups में assign करके manage करना आपकी responsibility होती है।

Linux में new user को add करने के लिए दो commands का use किया जाता है -

  1. useradd

  2. adduser

useradd Vs adduser

Linux में adduser Command , useradd Command की symbolic link ही है। और इनमे सबसे बड़ा difference यह है कि useradd command system के साथ compile की गयी native binary है, जबकि adduser Command एक Perl script है जो background में तो useradd binary ही use करती है।

चूंकि useradd Command native command है means इसे use करने के लिए आपको install नहीं करना पड़ेगा , और adduser Command use करने के लिए आपको install करना पड़ेगा।

इसके अलावा useradd Command द्वारा create किये गए user से सिर्फ user ही create होता है , extra configurations आपको अलग से manually set करनी पड़ेगी जबकि adduser Command new user के लिए सभी default configurations automatically set कर देती है।

***

इस article में हम useradd command के बारे में बात करेंगे।

Linux useradd Command

Linux में किसी new user को add करने के लिए useradd command का use किया जाता है। useradd command का general syntax कुछ इस तरह से होता है।

useradd [options] username

useradd के सभी available options को आप adduser --help या adduser -h command run करके देख सकते हैं।

useradd --help

जब भी useradd command को invoked किया जाता है तो command line में pass किये गए options के according new user account create हो जाता और default value /etc/default/useradd file में set हो जाती हैं।

useradd command /etc/login.defs file के content को भी read करती है। इस file में shadow password suite जैसे password expiration policy, ranges of user IDs used जब और काफी दूसरी configurations होती हैं।

Create a New User in Linux

new user को create करने के लिए useradd command को कुछ इस तरह से run किया जाता है ।

$ sudo useradd rahul

जब useradd command को बिना किसी options के साथ executed किया जाता है तो new user account , /etc/default/useradd file में specified default settings के साथ create हो जाता है।

अब नए create किये गए user से login करने से पहले आपको उसका password define करना पड़ेगा। password set करने के लिए sudo command के साथ passwd option को use किया जाता है।

$ sudo passwd rahul
New password:test
Retype new password:test
passwd: password updated successfully

ध्यान रहे new user account को create करने के लिए useradd command को root या कोई ऐसा user जिसके पास sudo privileges हैं वही run कर सकता है।

Login user

user create करने के बाद आप su username command का use करके system में login कर सकते हैं ।

$ whoami
ubuntu
$ su rahul
Password:
$ whoami
rahul

और logout करने के लिए आप exit use कर सकते हैं।

Linux useradd Options

अब different - different users को options के साथ create करने की कोशिश करेंगे।

Linux useradd -m

useradd -m command new user को home directory के साथ add करती है। directory का name username के according होता है

$ sudo  useradd -m   testuser

Linux user ID

जब भी कोई new user add होता है , तो उसकी एक unique ID होती है , by default Linux create करता है लेकिन आप चाहे तो user create करते time ही custom id भी assign कर सकते हैं।

जैसे current user की id जानने के लिए नीचे दी गयी command run -

$ id -u ubuntu 
1000

custom ID के साथ user create करने के लिए -u / --uid option का use किया जाता है।

$ sudo  useradd -u 23424 testuser rahul

Linux group ID

Linux में हर user किसी न किसी group से belong करता है , और हर group की भी एक unique id होती है , by default Linux में ubuntu group होता है , और create किया जाने वाला user भी by default उसी group में assign होता है।

current user का group देखने के लिए आप नीचे दिए गयी command run कर सकते हैं -

$ id -g ubuntu 
1000

Linux new user को की किसी particular group में add करने के लिए -g option का use किया जाता है।

$ sudo  useradd -u 1000 testuser rahul

ध्यान रहे new user को create करते समय जो group id आप assign कर रहे हैं , वो group exist होना चाहिए।

Recent Blogs

Loading ...

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook