source: postlfs/config/skel.xml@ b3d9df0

plabs/python-mods qt5new trunk
Last change on this file since b3d9df0 was b3d9df0, checked in by Xi Ruoyao <xry111@…>, 4 months ago

useradd: add instructions for creating new user with same UID/GID on another system

  • Property mode set to 100644
File size: 6.8 KB
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "" [
4 <!ENTITY % general-entities SYSTEM "../../general.ent">
5 %general-entities;
8<sect1 id="postlfs-config-skel" xreflabel="Configuring for Adding Users">
9 <?dbhtml filename="skel.html"?>
11 <sect1info>
12 <date>$Date$</date>
13 </sect1info>
15 <title>Configuring for Adding Users</title>
17 <indexterm zone="postlfs-config-skel">
18 <primary sortas="e-etc-skel">/etc/skel/*</primary>
19 </indexterm>
21 <indexterm zone="postlfs-config-skel">
22 <primary sortas="e-etc-default-useradd">/etc/default/useradd</primary>
23 </indexterm>
25 <para>
26 Together, the <command>/usr/sbin/useradd</command> command and <filename
27 class="directory">/etc/skel</filename> directory (both are easy to
28 set up and use) provide a way to assure new users are added to your LFS
29 system with the same beginning settings for things such as the
30 <envar>PATH</envar>, keyboard processing and other environmental variables.
31 Using these two facilities makes it easier to assure this initial state for
32 each new user added to the system.
33 </para>
35 <para>
36 The <filename class="directory">/etc/skel</filename> directory holds
37 copies of various initialization and other files that may be copied to the
38 new user's home directory when the <command>/usr/sbin/useradd</command>
39 program adds the new user.
40 </para>
42 <bridgehead renderas="sect5">Useradd</bridgehead>
44 <para>
45 The <command>useradd</command> program uses a collection of default
46 values kept in <filename>/etc/default/useradd</filename>. This file
47 is created in a base LFS installation by the
48 <application>Shadow</application> package. If it has been removed or
49 renamed, the <command>useradd</command> program uses some internal
50 defaults. You can see the default values by running
51 <command>/usr/sbin/useradd -D</command>.
52 </para>
54 <para>
55 To change these values, simply modify the
56 <filename>/etc/default/useradd</filename> file as the
57 <systemitem class='username'>root</systemitem> user. An alternative to
58 directly modifying the file is to run <command>useradd</command> as the
59 <systemitem class='username'>root</systemitem> user while supplying the
60 desired modifications on the command line. Information on how to do this
61 can be found in the <command>useradd</command> man page.
62 </para>
64 <bridgehead renderas="sect5">/etc/skel</bridgehead>
66 <para>
67 To get started, create an
68 <filename class="directory">/etc/skel</filename> directory and make sure it
69 is writable only by the system administrator, usually
70 <systemitem class="username">root</systemitem>. Creating the directory as
71 <systemitem class="username">root</systemitem> is the best way to go.
72 </para>
74 <para>
75 The mode of any files from this part of the book that you put in <filename
76 class="directory">/etc/skel</filename> should be writable only by the
77 owner. Also, since there is no telling what kind of sensitive information
78 a user may eventually place in their copy of these files, you should
79 make them unreadable by "group" and "other".
80 </para>
82 <para>
83 You can also put other files in
84 <filename class="directory">/etc/skel</filename> and
85 different permissions may be needed for them.
86 </para>
88 <para>
89 Decide which initialization files should be provided in every (or most)
90 new user's home directory. The decisions you make will affect what you
91 do in the next two sections, <xref linkend="postlfs-config-profile"/> and
92 <xref linkend="postlfs-config-vimrc"/>. Some or all of those files will be
93 useful for <systemitem class="username">root</systemitem>, any
94 already-existing users, and new users.
95 </para>
97 <para>
98 The files from those sections that you might want to place in
99 <filename class="directory">/etc/skel</filename> include
100 <filename>.inputrc</filename>, <filename>.bash_profile</filename>,
101 <filename>.bashrc</filename>, <filename>.bash_logout</filename>,
102 <filename>.dircolors</filename>, and <filename>.vimrc</filename>. If
103 you are unsure which of these should be placed there, just continue to
104 the following sections, read each section and any references provided,
105 and then make your decision.
106 </para>
108 <para>
109 You will run a slightly modified set of commands for files which are
110 placed in <filename class="directory">/etc/skel</filename>. Each section
111 will remind you of this. In brief, the book's commands have been written
112 for files <emphasis>not</emphasis> added to <filename class="directory">
113 /etc/skel</filename> and instead just sends the results to the user's
114 home directory. If the file is going to be in <filename class="directory">
115 /etc/skel</filename>, change the book's command(s) to send output there
116 instead and then just copy the file from <filename class="directory">
117 /etc/skel</filename> to the appropriate directories, like <filename
118 class="directory">/etc</filename>, <filename class="directory">~
119 </filename> or the home directory of any other user already in the system.
120 </para>
122 <bridgehead renderas="sect5">When Adding a User</bridgehead>
124 <para>
125 When adding a new user with <command>useradd</command>, use
126 the <option>-m</option> parameter, which tells
127 <command>useradd</command> to create the user's home directory and
128 copy files from <filename class="directory">/etc/skel</filename> (can be
129 overridden) to the new user's home directory. For example (perform as the
130 <systemitem class="username">root</systemitem> user):
131 </para>
133<screen role="root"><userinput>useradd -m <replaceable>&lt;newuser&gt;</replaceable></userinput></screen>
135 <para>
136 If you are sharing a <filename class="directory">/home</filename>
137 or <filename class="directory">/usr/src</filename> with another
138 Linux distro (for example, the host distro used for building LFS), you
139 can create a user with the same UID (and, same primary group GID) to
140 keep the file ownership consistent across the systems. First, on
141 <emphasis>the other distro</emphasis>, get the UID of the user and the
142 GID of the user's primary group:
143 </para>
145<screen role="nodump"><userinput>getent passwd <replaceable>&lt;username&gt;</replaceable> | cut -d ':' -f 3,4</userinput></screen>
147 <para>
148 The command should output the UID and GID, separated by a colon. Now
149 on the BLFS system, create the primary group and the user:
150 </para>
152<screen role="root"><userinput>groupadd -g <replaceable>&lt;GID&gt;</replaceable> <replaceable>&lt;username&gt;</replaceable> &amp;&amp;
153useradd -u <replaceable>&lt;UID&gt;</replaceable> -g <replaceable>&lt;username&gt;</replaceable> <replaceable>&lt;username&gt;</replaceable></userinput></screen>
Note: See TracBrowser for help on using the repository browser.