📄 pwdgroup.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=gb2312" />
<title>
6.7. Creating the passwd, group, log Files
</title>
<link rel="stylesheet" href="../stylesheets/lfs.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.68.1" />
<link rel="stylesheet" href="../stylesheets/lfs-print.css" type="text/css" media="print" />
</head>
<body id="lfs" class="6.1">
<div class="navheader">
<div class="headertitles">
<h4>
Linux From Scratch - Version 6.1
</h4>
<h3>
Chapter 6. 安装系统基础软件
</h3>
</div>
<ul class="headerlinks">
<li class="prev">
<a accesskey="p" href="createfiles.html" title="Creating Essential Symlinks">后退</a>
<p>
Creating Essential Symlinks
</p>
</li>
<li class="next">
<a accesskey="n" href="devices.html" title="Populating /dev">前进</a>
<p>
Populating /dev
</p>
</li>
<li class="up">
<a accesskey="u" href="chapter06.html" title="Chapter 6. 安装系统基础软件">上一级</a>.
</li>
<li class="home">
<a accesskey="h" href="../index.html" title="Linux From Scratch - Version 6.1">回首页</a>
</li>
</ul>
</div>
<div class="sect1" lang="zh_cn" xml:lang="zh_cn">
<div class="titlepage">
<h1 class="sect1">
6.7. 创建 passwd, group, log 文件
</h1>
</div>
<p>为了让 <span class="emphasis"><em>root</em></span> 用户可以登录而且用户名“root”可以被识别,在这里需要创建相应的 <tt class="filename">/etc/passwd</tt> 和 <tt class="filename">/etc/group</tt> 文件。
</p>
<p>
使用下面的命令创建 <tt class="filename">/etc/passwd</tt> 文件:
</p>
<pre class="userinput"><kbd class="command">cat > /etc/passwd << "EOF"
<tt class="literal">root:x:0:0:root:/root:/bin/bash</tt>
EOF</kbd></pre>
<p><span class="emphasis"><em>root</em></span> 的真正密码将在后面设置(“<span class="quote">x</span>” 在这里只是一个占位符)。
</p>
<p>下面的命令创建 <tt class="filename">/etc/group</tt> 文件:
</p>
<pre class="userinput"><kbd class="command">cat > /etc/group << "EOF"
<tt class="literal">root:x:0:
bin:x:1:
sys:x:2:
kmem:x:3:
tty:x:4:
tape:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:</tt>
EOF</kbd></pre>
<p>这里创建的用户组并不是什么标准所要求的部分,只是因为在随后 Udev 配置将要用到而以。Linux标准基础(LSB,详见<a href="http://www.linuxbase.org"><i>http://www.linuxbase.org</i></a>)只是推荐“root”用户组的 GID 为 0,另一个组“bin”的 GID 为 1 。其它所有的组名和 GID 均由系统管理员自由设定,因为比较好的软件包一般都不依赖于 GID ,而只是使用组名。
</p>
<p>既然完整的 Glibc 在 <a href="../chapter05/chapter05.html">Chapter 5</a> 中已经安装,而且 <tt class="filename">/etc/passwd</tt> 和 <tt class="filename">/etc/group</tt> 文件也已创建,用户名和组名可以开始使用。现在启动新的shell,驱除“I have no name!”的提示符:
</p>
<pre class="userinput"><kbd class="command">exec /tools/bin/bash --login +h</kbd></pre>
<p>注意这里使用了 <em class="parameter"><tt>+h</tt></em> 参数。这是告诉 <span><strong class="command">bash</strong></span> 不能使用哈希表查找外部路径。如果没有使用这个参数,则 <span><strong class="command">bash</strong></span> 将会记住已经执行的二进制代码的路径。为了让新编译安装的二进制代码可以马上投入使用,在这一章中,我们关闭了此功能。
</p>
<p>程序 <span><strong class="command">login</strong></span>, <span><strong class="command">agetty</strong></span>, <span><strong class="command">init</strong></span> (还有一些其它的程序) 使用一些 log 文件来记录信息,比如谁在什么时候登录了系统等等。然而如果文件不存在,这些程序则无法写入。下面初始化这些 log 文件,并设置适当的权限:
</p>
<pre class="userinput"><kbd class="command">touch /var/run/utmp /var/log/{btmp,lastlog,wtmp}
chgrp utmp /var/run/utmp /var/log/lastlog
chmod 664 /var/run/utmp /var/log/lastlog</kbd></pre>
<p>
<tt class="filename">/var/run/utmp</tt> 记录着现在登录的用户。<tt class="filename">/var/log/wtmp</tt> 记录所有的登录和登出。 <tt class="filename">/var/log/lastlog</tt> 记录每个用户最后的登录信息。 <tt class="filename">/var/log/btmp</tt> 记录错误的登录尝试。
</p>
</div>
<div class="navfooter">
<ul>
<li class="prev">
<a accesskey="p" href="createfiles.html" title="Creating Essential Symlinks">后退</a>
<p>
Creating Essential Symlinks
</p>
</li>
<li class="next">
<a accesskey="n" href="devices.html" title="Populating /dev">前进</a>
<p>
Populating /dev
</p>
</li>
<li class="up">
<a accesskey="u" href="chapter06.html" title="Chapter 6. 安装系统基础软件">上一级</a>.
</li>
<li class="home">
<a accesskey="h" href="../index.html" title="Linux From Scratch - Version 6.1">回首页</a>.
</li>
</ul>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -