<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>
<channel>
	<title>G-Loaded Journal &#187; User Management</title>
	<atom:link href="http://www.g-loaded.eu/tag/user-management/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.g-loaded.eu</link>
	<description>An open-source software and technology related journal</description>
	<lastBuildDate>Mon, 05 Dec 2011 19:55:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
		<item>
		<title>User management from the command line</title>
		<link>http://www.g-loaded.eu/2005/11/06/manage-users-from-the-command-line/</link>
		<comments>http://www.g-loaded.eu/2005/11/06/manage-users-from-the-command-line/#comments</comments>
		<pubDate>Sun, 06 Nov 2005 13:41:18 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[User Management]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/?p=71</guid>
		<description><![CDATA[This is a short article about the most common practices in user and group management from the command line. The information is specific to Fedora Core and Red Hat based distros, but would do for any distribution probably with slight differences in the command options.]]></description>
			<content:encoded><![CDATA[<p>Although Fedora comes with an excellent graphical tool to manage your users (<strong>system-config-users</strong>), there are times, for example when administering a server through SSH, that user management has to be done from command line.</p>
<p>All operations can be done using the following commands:<br />
<strong>id</strong>, <strong>useradd</strong>, <strong>usermod</strong>, <strong>userdel</strong>, <strong>groupadd</strong>, <strong>groupdel</strong>, <strong>groupmod</strong>, <strong>passwd</strong></p>
<p>These exist in every Linux distribution with slight differences in each command&#8217;s supported options. The following info applies to Fedora Core and other Red Had based distros.<br />
<span id="more-71"></span></p>
<h4>User info</h4>
<p>The <strong>id</strong> command prints information for a certain user. Use it like this:</p>
<pre class="console"># id username</pre>
<h4>Create a user</h4>
<p>To create a new user:</p>
<pre class="console"># useradd -c &quot;My Example User&quot; username
# passwd username</pre>
<p>The created user is initially in an inactive state. To activate the user you have to assign a password with <strong>passwd</strong>. Some useful useradd options include the following:<br />
<strong>-c</strong> : sets a comment for the user.<br />
<strong>-s</strong> : is used in order to define the user&#8217;s default login shell. If not used, then the system&#8217;s default shell becomes the user&#8217;s default login shell.<br />
<strong>-r</strong> : creates a user with UID&lt;500 (system account)<br />
<strong>-d</strong> : sets the user&#8217;s home directory. If not used, the default home directory is created (/home/username/)<br />
<strong>-M</strong> : the home directory is not created. This is useful when the directory already exists.</p>
<p>To create a user that does not have the ability to login to a shell, issue the following commands:</p>
<pre class="console"># useradd -c &quot;This user cannot login to a shell&quot; -s /sbin/nologin username
# passwd username</pre>
<h4>Change the user&#8217;s password</h4>
<p>To change a user&#8217;s password:</p>
<pre class="console"># passwd username</pre>
<p>If it&#8217;s used without specifying a username, then the currently logged in user&#8217;s password is changed.</p>
<h4>Add a user to a group</h4>
<p><strong>Usermod</strong> is used to modify a user account&#8217;s settings. Check the man page for all the available options. One useful use of this command is to <strong>add a user to a group</strong>:</p>
<pre class="console"># usermod -a -G group1 username</pre>
<p>The <strong>-a</strong> option is critical. The user is added to group1 while he continues to be a member of other groups. If it&#8217;s not used, then the user is added only to group1 and removed from any other groups. <strong>So, take note!</strong></p>
<h4>Remove a user from a group</h4>
<p>Removing a user from a group is a bit trickier. Unfortunately, there is no direct command, at least not in Fedora or RHEL, that can do that from command line. At first you need to get a list of groups that your user is a member of:</p>
<pre class="console"># id -nG username
group1 group2 group3 ....</pre>
<p>Then you need to put all these groups as a comma-separated list to the usermod <strong>-G</strong> option, <strong>except</strong> for the group from which you want the user to be removed. So, to remove the user from group2, issue the command:</p>
<pre class="console"># usermod -G group1,group3,... username</pre>
<h4>Lock and Unlock user accounts</h4>
<p>Other common usermod uses are to lock and unlock user accounts. To <strong>lock</strong> out a user:</p>
<pre class="console"># usermod -L username</pre>
<p>To <strong>unlock</strong> the user:</p>
<pre class="console"># usermod -U username</pre>
<h4>Delete a user</h4>
<p><strong>Userdel</strong> is used to delete a user account. If the <strong>-r</strong> option is used then the user&#8217;s home directory and mail spool are deleted too:</p>
<pre class="console"># userdel -r username</pre>
<h4>Create a new group</h4>
<p>To create a new group, issue the command:</p>
<pre class="console"># groupadd groupname</pre>
<p>The <strong>-r</strong> option can be used to create a group with GID&lt;500 (system).</p>
<h4>Change a group&#8217;s name</h4>
<p><strong>Groupmod</strong> can be used to change a group name:</p>
<pre class="console"># groupmod -n newgroupname groupname</pre>
<h4>Delete a group</h4>
<p><strong>Groupdel</strong> can delete a group:</p>
<pre class="console"># groupdel groupname</pre>
<p>In order to delete a user&#8217;s primary group (usually this is the group with name equal to the username) the respective user must be deleted previously.</p>
<p>You can find more info in the man pages, but these will do in most cases.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2005/11/06/manage-users-from-the-command-line/">User management from the command line</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2005/11/10/using-a-cups-printer-from-command-line/" rel="bookmark">Using a CUPS printer from command line</a></li>
<li><a href="http://www.g-loaded.eu/2008/12/08/access-gvfs-mounts-from-the-command-line/" rel="bookmark">Access gvfs mounts from the command line</a></li>
<li><a href="http://www.g-loaded.eu/2007/02/12/lock-out-a-user-after-n-failed-login-attempts/" rel="bookmark">Lock out a user after N failed login attempts</a></li>
<li><a href="http://www.g-loaded.eu/2007/11/18/problems-using-libnotify-for-user-to-user-notifications/" rel="bookmark">Problems using libnotify for User to User Notifications</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/10/ssh-with-keys/" rel="bookmark">Setup the SSH server to use keys for authentication</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2005/11/06/manage-users-from-the-command-line/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
	</channel>
</rss>

