﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-旅途-随笔分类-LINUX基础、管理</title><link>http://www.cppblog.com/mydriverc/category/11522.html</link><description>如果想飞得高，就该把地平线忘掉</description><language>zh-cn</language><lastBuildDate>Mon, 15 Mar 2010 05:45:16 GMT</lastBuildDate><pubDate>Mon, 15 Mar 2010 05:45:16 GMT</pubDate><ttl>60</ttl><item><title>超完整RedHat9.0-vsftp配置大全</title><link>http://www.cppblog.com/mydriverc/archive/2010/03/14/109709.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Sun, 14 Mar 2010 15:56:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2010/03/14/109709.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/109709.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2010/03/14/109709.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/109709.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/109709.html</trackback:ping><description><![CDATA[3.2&nbsp;VSFTP&nbsp;安全与效能兼备的ftp&nbsp;服务器&nbsp;<br>3.2.1&nbsp;VSFTP&nbsp;概述&nbsp;<br>FTP，file&nbsp;transfer&nbsp;protocol，这是档案传输的通讯协议，也是一般最常用来传送档案的方式。读者在使用RedHat9&nbsp;的时候，可能会感受到ftp&nbsp;server&nbsp;有一些改变：第一，就是ftp&nbsp;server&nbsp;只剩下vsftp，原有的wuftp&nbsp;等都没放入&nbsp;第二，就是vsftp&nbsp;从XINETD&nbsp;中独立出来，并将设定档从/etc/vsftpd.conf&nbsp;之中移到/etc/vsftpd/vsftpd.conf。&nbsp;<br>为什么做这样的改变？可以想见的是vsftp&nbsp;已有独立运作的能力，不需要XINETD&nbsp;来做更进一步的管控，并且类似sendmail、httpd、ssh、samba&nbsp;等，将设定文件的放入/etc&nbsp;下独立的目录。&nbsp;<br>FTP&nbsp;分为两类，一种为PORT&nbsp;FTP，也就是一般的FTP&nbsp;另一类是PASVFTP，分述如下：<br>PORT&nbsp;FTP&nbsp;<br>这是一般形式的FTP，首先会建立控制频道，默认值是port&nbsp;21，也就是跟port&nbsp;21&nbsp;建立联机，并透过此联机下达指令。第二，由FTP&nbsp;server&nbsp;端会建立数据传输频道，默认值为20，也就是跟port&nbsp;20&nbsp;建立联机，并透过port&nbsp;20&nbsp;作数据的传输。&nbsp;<br>PASV&nbsp;FTP&nbsp;<br>跟PORT&nbsp;FTP&nbsp;类似，首先会建立控制频道，默认值是port&nbsp;21，也就是跟port&nbsp;21&nbsp;建立联机，并透过此联机下达指令。第二，会由client&nbsp;端做出数据传输的请求，包括数据传输port&nbsp;的数字。&nbsp;<br>这两者的差异为何？PORT&nbsp;FTP&nbsp;当中的数据传输port&nbsp;是由FTP&nbsp;server&nbsp;指定，而PASV&nbsp;FTP&nbsp;的数据传输port&nbsp;是由FTP&nbsp;client&nbsp;决定。通常我们使用PASV&nbsp;FTP，是在有防火墙的环境之下，透过client&nbsp;与server&nbsp;的沟通，决定数据传输的port。<br><br>3.2.2&nbsp;范例&nbsp;<br><br>3.2.1.&nbsp;直接启动VSFTP&nbsp;服务&nbsp;<br>这个范例是套用RedHat&nbsp;的预设范例,直接启动vsftp。&nbsp;<br>[root@relay&nbsp;vsftpd]#&nbsp;/sbin/service&nbsp;vsftpd&nbsp;start&nbsp;<br>Starting&nbsp;vsftpd&nbsp;for&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br><br>3.2.2.&nbsp;更换port&nbsp;提供服务：将预设的port&nbsp;21&nbsp;更换为2121<br>为了安全，或是以port&nbsp;来区隔不同的ftp&nbsp;服务，我们可能会将ftp&nbsp;port&nbsp;改为21&nbsp;之外的port，那么，可参考以下步骤。&nbsp;<br>Step1.&nbsp;修改/etc/vsftpd/vsftpd.conf&nbsp;<br>新增底下一行&nbsp;<br>listen_port=2121&nbsp;<br>Step2.&nbsp;重新启动vsftpd&nbsp;<br>[root@home&nbsp;vsftpd]#&nbsp;/sbin/service&nbsp;vsftpd&nbsp;restart&nbsp;<br>Shutting&nbsp;down&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br>Starting&nbsp;vsftpd&nbsp;for&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br><br>3.2.3.&nbsp;特定使用者peter、john&nbsp;不得变更目录&nbsp;<br>使用者的预设目录为/home/username，若是我们不希望使用者在ftp&nbsp;时能够&nbsp;<br>切换到上一层目录/home，则可参考以下步骤。&nbsp;<br>Step1.&nbsp;修改/etc/vsftpd/vsftpd.conf&nbsp;<br>将底下三行&nbsp;<br>#chroot_list_enable=YES&nbsp;<br>#&nbsp;(default&nbsp;follows)&nbsp;<br>#chroot_list_file=/etc/vsftpd.chroot_list&nbsp;<br>改为&nbsp;<br>chroot_list_enable=YES&nbsp;<br>#&nbsp;(default&nbsp;follows)&nbsp;<br>chroot_list_file=/etc/vsftpd/chroot_list&nbsp;<br>Step2.&nbsp;新增一个档案:&nbsp;/etc/vsftpd/chroot_list&nbsp;<br>内容增加两行：&nbsp;<br>peter&nbsp;<br>john&nbsp;<br>Step3.&nbsp;重新启动vsftpd&nbsp;<br>[root@home&nbsp;vsftpd]#&nbsp;/sbin/service&nbsp;vsftpd&nbsp;restart&nbsp;<br>Shutting&nbsp;down&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br>Starting&nbsp;vsftpd&nbsp;for&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br>若是peter&nbsp;欲切换到根目录以外的目录，则会出现以下警告：&nbsp;<br>ftp&gt;&nbsp;cd&nbsp;/home&nbsp;<br>550&nbsp;Failed&nbsp;to&nbsp;change&nbsp;directory.&nbsp;<br><br>3.2.4.&nbsp;取消anonymous&nbsp;登入&nbsp;<br>若是读者的主机不希望使用者匿名登入，则可参考以下步骤。<br>Step1.&nbsp;修改/etc/vsftpd/vsftpd.conf&nbsp;<br>将&nbsp;<br>anonymous_enable=YES&nbsp;<br>改为&nbsp;<br>anonymous_enable=NO&nbsp;<br>Step2.&nbsp;重新启动vsftpd&nbsp;<br>[root@home&nbsp;vsftpd]#&nbsp;/sbin/service&nbsp;vsftpd&nbsp;restart&nbsp;<br>Shutting&nbsp;down&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br>Starting&nbsp;vsftpd&nbsp;for&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br><br>3.2.5.&nbsp;安排欢迎话语<br>若是我们希望使用者在登入时，能够看到欢迎话语，可能包括对该主机的说明，或是目录的介绍，可参考以下步骤。<br>首先确定在/etc/vsftpd/vsftpd.conf&nbsp;当中是否有底下这一行&nbsp;<br>dirmessage_enable=YES&nbsp;<br>RedHat9&nbsp;的默认值是有上面这行的。&nbsp;<br>接着，在各目录之中，新增名为.message&nbsp;的档案，再这边假设有一个使用者test1，且此使用者的根目录下有个目录名为abc，那首先我们在/home/test1&nbsp;<br>之下新增.message，内容如下：&nbsp;<br>Hello~&nbsp;Welcome&nbsp;to&nbsp;the&nbsp;home&nbsp;directory&nbsp;<br>This&nbsp;is&nbsp;for&nbsp;test&nbsp;only...&nbsp;<br>接着，在/home/test1/abc&nbsp;的目录下新增.message，内容如下：&nbsp;<br>Welcome&nbsp;to&nbsp;abc's&nbsp;directory&nbsp;<br>This&nbsp;is&nbsp;subdir...&nbsp;<br>那么，当使用者test1&nbsp;登入时，会看到以下讯息：&nbsp;<br>230-&nbsp;Hello~&nbsp;Welcome&nbsp;to&nbsp;the&nbsp;home&nbsp;directory&nbsp;<br>230-&nbsp;<br>230-&nbsp;This&nbsp;is&nbsp;for&nbsp;test&nbsp;only...&nbsp;<br>230-&nbsp;<br>若是切换到abc&nbsp;的目录，则会出现以下讯息：&nbsp;<br>250-&nbsp;Welcome&nbsp;to&nbsp;abc's&nbsp;directory&nbsp;<br>250-&nbsp;<br>250-&nbsp;This&nbsp;is&nbsp;subdir&nbsp;...&nbsp;<br><br>3.2.6.&nbsp;对于每一个联机，以独立的process&nbsp;来运作<br>一般启动vsftp&nbsp;时，我们只会看到一个名为vsftpd&nbsp;的process&nbsp;在运作，但若是读者希望每一个联机，都能以独立的process&nbsp;来呈现，则可执行以下步骤。<br>Step1.&nbsp;修改/etc/vsftpd/vsftpd.conf&nbsp;<br>新增底下一行&nbsp;<br>setproctitle_enable=YES&nbsp;<br>Step2.&nbsp;重新启动vsftpd&nbsp;<br>[root@home&nbsp;vsftpd]#&nbsp;/sbin/service&nbsp;vsftpd&nbsp;restart&nbsp;<br>Shutting&nbsp;down&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br>Starting&nbsp;vsftpd&nbsp;for&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br>使用ps&nbsp;-ef&nbsp;的指令，可以看告不同使用者联机的情形，如下图所示：&nbsp;<br>[root@home&nbsp;vsftpd]#&nbsp;ps&nbsp;-ef|grep&nbsp;ftp&nbsp;<br>root&nbsp;2090&nbsp;1&nbsp;0&nbsp;16:41&nbsp;pts/0&nbsp;00:00:00&nbsp;vsftpd:&nbsp;LISTENER&nbsp;<br>nobody&nbsp;2120&nbsp;2090&nbsp;0&nbsp;17:18&nbsp;?&nbsp;00:00:00&nbsp;vsftpd:&nbsp;192.168.10.244:&nbsp;<br>connected&nbsp;<br>test1&nbsp;2122&nbsp;2120&nbsp;0&nbsp;17:18&nbsp;?&nbsp;00:00:00&nbsp;vsftpd:&nbsp;192.168.10.244/test1:&nbsp;<br>IDLE&nbsp;<br>nobody&nbsp;2124&nbsp;2090&nbsp;0&nbsp;17:19&nbsp;?&nbsp;00:00:00&nbsp;vsftpd:&nbsp;192.168.10.244:&nbsp;<br>connected&nbsp;<br>test2&nbsp;2126&nbsp;2124&nbsp;0&nbsp;17:19&nbsp;?&nbsp;00:00:00&nbsp;vsftpd:&nbsp;192.168.10.244/test2:&nbsp;<br>IDLE&nbsp;<br>root&nbsp;2129&nbsp;1343&nbsp;0&nbsp;17:20&nbsp;pts/0&nbsp;00:00:00&nbsp;grep&nbsp;ftp&nbsp;<br>[root@home&nbsp;vsftpd]#<br><br>3.2.7.&nbsp;限制传输档案的速度：<br>本机的使用者最高速度为200KBytes/s，匿名登入者所能使用的最高速度为50KBytes/s<br>Step1.&nbsp;修改/etc/vsftpd/vsftpd.conf&nbsp;<br>新增底下两行&nbsp;<br>anon_max_rate=50000&nbsp;<br>local_max_rate=200000&nbsp;<br>Step2.&nbsp;重新启动vsftpd&nbsp;<br>[root@home&nbsp;vsftpd]#&nbsp;/sbin/service&nbsp;vsftpd&nbsp;restart&nbsp;<br>Shutting&nbsp;down&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br>Starting&nbsp;vsftpd&nbsp;for&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br>在这边速度的单位为Bytes/s，其中anon_max_rate&nbsp;所限制的是匿名登入的&nbsp;<br>使用者，而local_max_rate&nbsp;所限制的是本机的使用者。VSFTPD&nbsp;对于速度的限&nbsp;<br>制，范围大概在80%到120%之间，也就是我们限制最高速度为100KBytes/s，&nbsp;<br>但实际的速度可能在80KBytes/s&nbsp;到120KBytes/s&nbsp;之间，当然，若是频宽不足&nbsp;<br>时，数值会低于此限制。<br><br>3.2.8.&nbsp;针对不同的使用者限制不同的速度：<br>假设test1&nbsp;所能使用的最高速度为250KBytes/s，test2&nbsp;所能使用的最高速度为500KBytes/s。&nbsp;<br>Step1.&nbsp;修改/etc/vsftpd/vsftpd.conf&nbsp;<br>新增底下一行&nbsp;<br>user_config_dir=/etc/vsftpd/userconf&nbsp;<br>Step2.&nbsp;新增一个目录：/etc/vsftpd/userconf&nbsp;<br>mkdir&nbsp;/etc/vsftpd/userconf&nbsp;<br>Step3.&nbsp;在/etc/vsftpd/userconf&nbsp;之下新增一个名为test1&nbsp;的档案&nbsp;<br>内容增加一行：&nbsp;<br>local_max_rate=250000&nbsp;<br>Step4.&nbsp;在/etc/vsftpd/userconf&nbsp;之下新增一个名为test2&nbsp;的档案&nbsp;<br>内容增加一行：&nbsp;<br>local_max_rate=500000&nbsp;<br>Step5.&nbsp;重新启动vsftpd&nbsp;<br>[root@home&nbsp;vsftpd]#&nbsp;/sbin/service&nbsp;vsftpd&nbsp;restart&nbsp;<br>Shutting&nbsp;down&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br>Starting&nbsp;vsftpd&nbsp;for&nbsp;vsftpd:&nbsp;OK&nbsp;]<br><br>3.2.9-1.&nbsp;建置一个防火墙下的ftp&nbsp;server，使用PORT&nbsp;FTP&nbsp;mode：<br>预设的ftp&nbsp;port:21&nbsp;以及ftp&nbsp;data&nbsp;port:20&nbsp;<br>启动VSFTPD&nbsp;之后执行以下两行指令，只允许port&nbsp;21&nbsp;以及port&nbsp;20&nbsp;开放，其它关闭。&nbsp;<br>iptables&nbsp;-A&nbsp;INPUT&nbsp;-p&nbsp;tcp&nbsp;-m&nbsp;multiport&nbsp;--dport&nbsp;21,20&nbsp;-j&nbsp;ACCEPT&nbsp;<br>iptables&nbsp;-A&nbsp;INPUT&nbsp;-p&nbsp;tcp&nbsp;-j&nbsp;REJECT&nbsp;--reject-with&nbsp;tcp-reset<br><br>3.2.9-2.&nbsp;建置一个防火墙下的ftp&nbsp;server，使用PORT&nbsp;FTP&nbsp;mode：<br>ftp&nbsp;port:2121&nbsp;以及ftp&nbsp;data&nbsp;port:2020&nbsp;<br>Step1.&nbsp;执行以下两行指令，只允许port&nbsp;2121&nbsp;以及port&nbsp;2020&nbsp;开放，其它关闭。&nbsp;<br>iptables&nbsp;-A&nbsp;INPUT&nbsp;-p&nbsp;tcp&nbsp;-m&nbsp;multiport&nbsp;--dport&nbsp;2121,2020&nbsp;-j&nbsp;ACCEPT&nbsp;<br>iptables&nbsp;-A&nbsp;INPUT&nbsp;-p&nbsp;tcp&nbsp;-j&nbsp;REJECT&nbsp;--reject-with&nbsp;tcp-reset&nbsp;<br>Step2.&nbsp;修改/etc/vsftpd/vsftpd.conf&nbsp;<br>新增底下两行&nbsp;<br>listen_port=2121&nbsp;<br>ftp_data_port=2020&nbsp;<br>Step3.&nbsp;重新启动vsftpd&nbsp;<br>[root@home&nbsp;vsftpd]#&nbsp;/sbin/service&nbsp;vsftpd&nbsp;restart&nbsp;<br>Shutting&nbsp;down&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br>Starting&nbsp;vsftpd&nbsp;for&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br>在这边要注意，8、9&nbsp;两个例子中，ftp&nbsp;client（如cuteftp）的联机方式不能够选择passive&nbsp;mode，否则无法建立数据的联机。也就是读者可以连上ftp&nbsp;<br>server，但是执行ls、get&nbsp;等等的指令时，便无法运作。<br><br>3.2.10.&nbsp;建置一个防火墙下的ftp&nbsp;server，使用PASS&nbsp;FTP&nbsp;mode：<br>ftp&nbsp;port:2121&nbsp;以及ftp&nbsp;data&nbsp;port&nbsp;从9981&nbsp;到9986。&nbsp;<br>Step1.&nbsp;执行以下两行指令，只允许port&nbsp;2121&nbsp;以及port&nbsp;9981-9990&nbsp;开放，其它关闭。&nbsp;<br>iptables&nbsp;-A&nbsp;INPUT&nbsp;-p&nbsp;tcp&nbsp;-m&nbsp;multiport&nbsp;--dport&nbsp;<br>2121,9981,9982,9983,9984,9985,9986,9987,9988,9989,9990&nbsp;-j&nbsp;ACCEPT&nbsp;<br>iptables&nbsp;-A&nbsp;INPUT&nbsp;-p&nbsp;tcp&nbsp;-j&nbsp;REJECT&nbsp;--reject-with&nbsp;tcp-reset&nbsp;<br>Step2.&nbsp;修改/etc/vsftpd/vsftpd.conf&nbsp;<br>新增底下四行&nbsp;<br>listen_port=2121&nbsp;<br>pasv_enable=YES&nbsp;<br>pasv_min_port=9981&nbsp;<br>pasv_max_port=9986&nbsp;<br>Step3.&nbsp;重新启动vsftpd&nbsp;<br>[root@home&nbsp;vsftpd]#&nbsp;/sbin/service&nbsp;vsftpd&nbsp;restart&nbsp;<br>Shutting&nbsp;down&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br>Starting&nbsp;vsftpd&nbsp;for&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br>在这边要注意，在10&nbsp;这个例子中，ftp&nbsp;client（如cuteftp）的联机方式必须选择passive&nbsp;mode，否则无法建立数据的联机。也就是读者可以连上ftp&nbsp;server，但是执行ls,get&nbsp;等等的指令时，便无法运作。<br><br>3.2.11.&nbsp;将vsftpd&nbsp;与TCP_wrapper&nbsp;结合<br>若是读者希望直接在/etc/hosts.allow&nbsp;之中定义允许或是拒绝的来源地址，可执行以下步骤。这是简易的防火墙设定。&nbsp;<br>Step1.&nbsp;确定/etc/vsftpd/vsftpd.conf&nbsp;之中tcp_wrappers&nbsp;的设定为YES，如下图所&nbsp;<br>示：&nbsp;<br>tcp_wrappers=YES&nbsp;<br>这是RedHat9&nbsp;的默认值，基本上不需修改。&nbsp;<br>Step2.&nbsp;重新启动vsftpd&nbsp;<br>[root@home&nbsp;vsftpd]#&nbsp;/sbin/service&nbsp;vsftpd&nbsp;restart&nbsp;<br>Shutting&nbsp;down&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br>Starting&nbsp;vsftpd&nbsp;for&nbsp;vsftpd:&nbsp;OK&nbsp;]&nbsp;<br>Step3.&nbsp;设定/etc/hosts.allow，譬如提供111.22.33.4&nbsp;以及10.1.1.1&nbsp;到10.1.1.254&nbsp;连&nbsp;<br>线，则可做下图之设定：&nbsp;<br>vsftpd&nbsp;:&nbsp;111.22.33.4&nbsp;10.1.1.&nbsp;:&nbsp;allow&nbsp;<br>ALL&nbsp;:&nbsp;ALL&nbsp;:&nbsp;DENY<br><br>3.2.12.&nbsp;将vsftpd&nbsp;并入XINETD&nbsp;<br>若是读者希望将vsftpd&nbsp;并入XINETD&nbsp;之中，也就是7.x&nbsp;版的预设设定，那&nbsp;<br>么读者可以执行以下步骤。&nbsp;<br>Step1.&nbsp;修改/etc/vsftpd/vsftpd.conf&nbsp;<br>将&nbsp;<br>listen=YES&nbsp;<br>改为&nbsp;<br>listen=NO&nbsp;<br>Step2.&nbsp;新增一个档案：&nbsp;/etc/xinetd.d/vsftpd&nbsp;<br>内容如下：&nbsp;<br>service&nbsp;vsftpd&nbsp;<br>{&nbsp;<br>disable&nbsp;=&nbsp;no&nbsp;<br>socket_type&nbsp;=&nbsp;stream&nbsp;<br>wait&nbsp;=&nbsp;no&nbsp;<br>user&nbsp;=&nbsp;root&nbsp;<br>server&nbsp;=&nbsp;/usr/sbin/vsftpd&nbsp;<br>port&nbsp;=&nbsp;21&nbsp;<br>log_on_success&nbsp;+=&nbsp;PID&nbsp;HOST&nbsp;DURATION&nbsp;<br>log_on_failure&nbsp;+=&nbsp;HOST&nbsp;<br>}&nbsp;<br>Step3.&nbsp;重新启动xinetd&nbsp;<br>[root@home&nbsp;vsftpd]#&nbsp;/sbin/service&nbsp;xinetd&nbsp;restart&nbsp;<br>Stopping&nbsp;xinetd:&nbsp;OK&nbsp;]&nbsp;<br>Starting&nbsp;xinetd:&nbsp;OK&nbsp;]&nbsp;<br><br>3.2.3&nbsp;设定档说明<br>在范例中，有些省略的设定可以在这边找到，譬如联机的总数、同一个位址的联机数、显示档案拥有者的名称等等，希望读者细读后，可以做出最适合自己的设定。<br>格式<br>vsftpd.conf&nbsp;的内容非常单纯，每一行即为一项设定。若是空白行或是开头为#的一行，将会被忽略。内容的格式只有一种，如下所示&nbsp;<br>option=value&nbsp;<br>要注意的是，等号两边不能加空白，不然是不正确的设定。&nbsp;<br>＝＝＝ascii&nbsp;设定＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝&nbsp;<br>ascii_download_enable&nbsp;<br>管控是否可用ASCII&nbsp;模式下载。默认值为NO。&nbsp;<br>ascii_upload_enable&nbsp;<br>管控是否可用ASCII&nbsp;模式上传。默认值为NO。&nbsp;<br>＝＝＝个别使用者设定＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝&nbsp;<br>chroot_list_enable&nbsp;<br>如果启动这项功能，则所有的本机使用者登入均可进到根目录之外的数据夹，除了列&nbsp;<br>在/etc/vsftpd.chroot_list&nbsp;之中的使用者之外。默认值为NO。&nbsp;<br>userlist_enable&nbsp;<br>用法：YES/NO&nbsp;<br>若是启动此功能，则会读取/etc/vsftpd.user_list&nbsp;当中的使用者名称。此项功能可以在询问密码前就出现失败讯息，而不需要检验密码的程序。默认值为关闭。&nbsp;<br>userlist_deny&nbsp;<br>用法：YES/NO&nbsp;<br>这个选项只有在userlist_enable&nbsp;启动时才会被检验。如果将这个选项设为YES，则在/etc/vsftpd.user_list&nbsp;中的使用者将无法登入&nbsp;若设为NO&nbsp;，&nbsp;则只有在&nbsp;<br>/etc/vsftpd.user_list&nbsp;中的使用者才能登入。而且此项功能可以在询问密码前就出现错误讯息，而不需要检验密码的程序。&nbsp;<br>user_config_dir&nbsp;<br>定义个别使用者设定文件所在的目录，例如定义user_config_dir=/etc/vsftpd/userconf，且主机上有使用者test1,test2，那我们可以在user_config_dir&nbsp;的目录新增文件名为test1&nbsp;以及test2。若是test1&nbsp;登入，则会读取user_config_dir&nbsp;下的test1&nbsp;这个档案内的设定。默认值为无。&nbsp;<br>＝＝＝欢迎语设定＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝&nbsp;<br>dirmessage_enable&nbsp;<br>如果启动这个选项，使用者第一次进入一个目录时，会检查该目录下是否有.message这个档案，若是有，则会出现此档案的内容，通常这个档案会放置欢迎话语，或是对该目录的说明。默认值为开启。&nbsp;<br>banner_file&nbsp;<br>当使用者登入时，会显示此设定所在的档案内容，通常为欢迎话语或是说明。默认值为无。&nbsp;<br>ftpd_banner&nbsp;<br>这边可定义欢迎话语的字符串，相较于banner_file&nbsp;是档案的形式，而ftpd_banner&nbsp;是字串的格式。预设为无。&nbsp;<br>＝＝＝特殊安全设定＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝&nbsp;<br>chroot_local_user&nbsp;<br>如果设定为YES，那么所有的本机的使用者都可以切换到根目录以外的数据夹。预设值为NO。&nbsp;<br>hide_ids&nbsp;<br>如果启动这项功能，所有档案的拥有者与群组都为ftp，也就是使用者登入使用ls&nbsp;-al之类的指令，所看到的档案拥有者跟群组均为ftp。默认值为关闭。&nbsp;<br>ls_recurse_enable&nbsp;<br>若是启动此功能，则允许登入者使用ls&nbsp;-R&nbsp;这个指令。默认值为NO。&nbsp;<br>write_enable&nbsp;<br>用法：YES/NO&nbsp;<br>这个选项可以控制FTP&nbsp;的指令是否允许更改file&nbsp;system，譬如STOR、DELE、&nbsp;<br>RNFR、RNTO、MKD、RMD、APPE&nbsp;以及SITE。预设是关闭。&nbsp;<br>setproctitle_enable&nbsp;<br>用法：YES/NO&nbsp;<br>启动这项功能，vsftpd&nbsp;会将所有联机的状况已不同的process&nbsp;呈现出来，换句话说，使用ps&nbsp;-ef&nbsp;这类的指令就可以看到联机的状态。默认值为关闭。&nbsp;<br>tcp_wrappers&nbsp;<br>用法：YES/NO&nbsp;<br>如果启动，则会将vsftpd&nbsp;与tcp&nbsp;wrapper&nbsp;结合，也就是可以在/etc/hosts.allow&nbsp;与/etc/hosts.deny&nbsp;中定义可联机或是拒绝的来源地址。&nbsp;<br>pam_service_name&nbsp;<br>这边定义PAM&nbsp;所使用的名称，预设为vsftpd。&nbsp;<br>secure_chroot_dir&nbsp;<br>这个选项必须指定一个空的数据夹且任何登入者都不能有写入的权限，当vsftpd&nbsp;不需要file&nbsp;system&nbsp;的权限时，就会将使用者限制在此数据夹中。默认值为/usr/share/empty&nbsp;<br><br>＝＝＝纪录文件设定＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝&nbsp;<br>xferlog_enable&nbsp;<br>用法：YES/NO&nbsp;<br>如果启动，上传与下载的信息将被完整纪录在底下xferlog_file&nbsp;所定义的档案中。预设为开启。&nbsp;<br>xferlog_file&nbsp;<br>这个选项可设定纪录文件所在的位置，默认值为/var/log/vsftpd.log。&nbsp;<br>xferlog_std_format&nbsp;<br>如果启动，则纪录文件将会写为xferlog&nbsp;的标准格式，如同wu-ftpd&nbsp;一般。默认值为关闭。&nbsp;<br><br>＝＝＝逾时设定＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝&nbsp;<br>accept_timeout&nbsp;<br>接受建立联机的逾时设定，单位为秒。默认值为60。&nbsp;<br>connect_timeout&nbsp;<br>响应PORT&nbsp;方式的数据联机的逾时设定，单位为秒。默认值为60。&nbsp;<br>data_connection_timeout&nbsp;<br>建立数据联机的逾时设定。默认值为300&nbsp;秒。&nbsp;<br>idle_session_timeout&nbsp;<br>发呆的逾时设定，若是超出这时间没有数据的传送或是指令的输入，则会强迫断线，单位为秒。默认值为300。&nbsp;<br>＝＝＝速率限制＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝&nbsp;<br>anon_max_rate&nbsp;<br>匿名登入所能使用的最大传输速度，单位为每秒多少bytes，0&nbsp;表示不限速度。默认值为0。&nbsp;<br>local_max_rate&nbsp;<br>本机使用者所能使用的最大传输速度，单位为每秒多少bytes，0&nbsp;表示不限速度。预设值为0。&nbsp;<br>＝＝＝新增档案权限设定＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝&nbsp;<br>anon_umask&nbsp;<br>匿名登入者新增档案时的umask&nbsp;数值。默认值为077。&nbsp;<br>file_open_mode&nbsp;<br>上传档案的权限，与chmod&nbsp;所使用的数值相同。默认值为0666。&nbsp;<br>local_umask&nbsp;<br>本机登入者新增档案时的umask&nbsp;数值。默认值为077。&nbsp;<br>＝＝＝port&nbsp;设定＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝&nbsp;<br>connect_from_port_20&nbsp;<br>用法：YES/NO&nbsp;<br>若设为YES，则强迫ftp-data&nbsp;的数据传送使用port&nbsp;20。默认值为YES。&nbsp;<br>ftp_data_port&nbsp;<br>设定ftp&nbsp;数据联机所使用的port。默认值为20。&nbsp;<br>listen_port&nbsp;<br>FTP&nbsp;server&nbsp;所使用的port。默认值为21。&nbsp;<br>pasv_max_port&nbsp;<br>建立资料联机所可以使用port&nbsp;范围的上界，0&nbsp;表示任意。默认值为0。&nbsp;<br>pasv_min_port&nbsp;<br>建立资料联机所可以使用port&nbsp;范围的下界，0&nbsp;表示任意。默认值为0。&nbsp;<br>＝＝＝其它＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝&nbsp;<br>anon_root&nbsp;<br>使用匿名登入时，所登入的目录。默认值为无。&nbsp;<br>local_enable&nbsp;<br>用法：YES/NO&nbsp;<br>启动此功能则允许本机使用者登入。默认值为YES。&nbsp;<br>local_root&nbsp;<br>本机使用者登入时，将被更换到定义的目录下。默认值为无。&nbsp;<br>text_userdb_names&nbsp;<br>用法：YES/NO&nbsp;<br>当使用者登入后使用ls&nbsp;-al&nbsp;之类的指令查询该档案的管理权时，预设会出现拥有者的UID，而不是该档案拥有者的名称。若是希望出现拥有者的名称，则将此功能开启。默认值为NO。&nbsp;<br>pasv_enable&nbsp;<br>若是设为NO，则不允许使用PASV&nbsp;的模式建立数据的联机。默认值为开启。&nbsp;<br>＝＝＝更换档案所有权＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝&nbsp;<br>chown_uploads&nbsp;<br>用法：YES/NO&nbsp;<br>若是启动，所有匿名上传数据的拥有者将被更换为chown_username&nbsp;当中所设定的使用者。这样的选项对于安全及管理，是很有用的。默认值为NO。&nbsp;<br>chown_username&nbsp;<br>这里可以定义当匿名登入者上传档案时，该档案的拥有者将被置换的使用者名称。预设值为root。&nbsp;<br>＝＝＝guest&nbsp;设定＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝&nbsp;<br>guest_enable&nbsp;<br>用法：YES/NO&nbsp;<br>若是启动这项功能，所有的非匿名登入者都视为guest。默认值为关闭。&nbsp;<br>guest_username&nbsp;<br>这里将定义guest&nbsp;的使用者名称。默认值为ftp。&nbsp;<br>＝＝＝anonymous&nbsp;设定＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝&nbsp;<br>anonymous_enable&nbsp;<br>用法：YES/NO&nbsp;<br>管控使否允许匿名登入，YES&nbsp;为允许匿名登入，NO&nbsp;为不允许。默认值为YES。&nbsp;<br>no_anon_password&nbsp;<br>若是启动这项功能，则使用匿名登入时，不会询问密码。默认值为NO。&nbsp;<br>anon_mkdir_write_enable&nbsp;<br>用法：YES/NO&nbsp;<br>如果设为YES，匿名登入者会被允许新增目录，当然，匿名使用者必须要有对上层目录的写入权。默认值为NO。&nbsp;<br>anon_other_write_enable&nbsp;<br>用法：YES/NO&nbsp;<br>如果设为YES，匿名登入者会被允许更多于上传与建立目录之外的权限，譬如删除或是更名。默认值为NO。&nbsp;<br>anon_upload_enable&nbsp;<br>用法：YES/NO&nbsp;<br>如果设为YES，匿名登入者会被允许上传目录的权限，当然，匿名使用者必须要有对上层目录的写入权。默认值为NO。&nbsp;<br>anon_world_readable_only&nbsp;<br>用法：YES/NO&nbsp;<br>如果设为YES，匿名登入者会被允许下载可阅读的档案。默认值为YES。&nbsp;<br>ftp_username&nbsp;<br>定义匿名登入的使用者名称。默认值为ftp。&nbsp;<br>deny_email_enable&nbsp;<br>若是启动这项功能，则必须提供一个档案/etc/vsftpd.banner_emails，内容为email&nbsp;<br>address。若是使用匿名登入，则会要求输入email&nbsp;address，若输入的email&nbsp;address&nbsp;在此档案内，则不允许联机。默认值为NO。&nbsp;<br>＝＝＝Standalone&nbsp;选项＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝&nbsp;<br>listen&nbsp;<br>用法：YES/NO&nbsp;<br>若是启动，则vsftpd&nbsp;将会以独立运作的方式执行，若是vsftpd&nbsp;独立执行，如RedHat9的默认值，则必须启动&nbsp;若是vsftpd&nbsp;包含在xinetd&nbsp;之中，则必须关闭此功能，如RedHat8。在RedHat9&nbsp;的默认值为YES。&nbsp;<br>listen_address&nbsp;<br>若是vsftpd&nbsp;使用standalone&nbsp;的模式，可使用这个参数定义使用哪个IP&nbsp;address&nbsp;提供这项服务，若是主机上只有定义一个IP&nbsp;address，则此选项不需使用，若是有多个IP&nbsp;address，可定义在哪个IP&nbsp;address&nbsp;上提供ftp&nbsp;服务。若是不设定，则所有的IP&nbsp;address均会提供此服务。默认值为无。&nbsp;<br>max_clients&nbsp;<br>若是vsftpd&nbsp;使用standalone&nbsp;的模式，可使用这个参数定义最大的总联机数。超过这个数目将会拒绝联机，0&nbsp;表示不限。默认值为0。&nbsp;<br>max_per_ip&nbsp;<br>若是vsftpd&nbsp;使用standalone&nbsp;的模式，可使用这个参数定义每个ip&nbsp;address&nbsp;所可以联机的数目。超过这个数目将会拒绝联机，0&nbsp;表示不限。默认值为0。&nbsp;<br>＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝&nbsp;<br><br>3.2.4&nbsp;FTP&nbsp;数字代码的意义&nbsp;<br>110&nbsp;重新启动标记应答。&nbsp;<br>120&nbsp;服务在多久时间内ready。&nbsp;<br>125&nbsp;数据链路埠开启，准备传送。&nbsp;<br>150&nbsp;文件状态正常，开启数据连接端口。&nbsp;<br>200&nbsp;命令执行成功。&nbsp;<br>202&nbsp;命令执行失败。&nbsp;<br>211&nbsp;系统状态或是系统求助响应。&nbsp;<br>212&nbsp;目录的状态。&nbsp;<br>213&nbsp;文件的状态。&nbsp;<br>214&nbsp;求助的讯息。&nbsp;<br>215&nbsp;名称系统类型。&nbsp;<br>220&nbsp;新的联机服务ready。&nbsp;<br>221&nbsp;服务的控制连接埠关闭，可以注销。&nbsp;<br>225&nbsp;数据连结开启，但无传输动作。&nbsp;<br>226&nbsp;关闭数据连接端口，请求的文件操作成功。&nbsp;<br>227&nbsp;进入passive&nbsp;mode。&nbsp;<br>230&nbsp;使用者登入。&nbsp;<br>250&nbsp;请求的文件操作完成。&nbsp;<br>257&nbsp;显示目前的路径名称。&nbsp;<br>331&nbsp;用户名称正确，需要密码。&nbsp;<br>332&nbsp;登入时需要账号信息。&nbsp;<br>350&nbsp;请求的操作需要进一部的命令。&nbsp;<br>421&nbsp;无法提供服务，关闭控制连结。&nbsp;<br>425&nbsp;无法开启数据链路。&nbsp;<br>426&nbsp;关闭联机，终止传输。&nbsp;<br>450&nbsp;请求的操作未执行。&nbsp;<br>451&nbsp;命令终止：有本地的错误。&nbsp;<br>452&nbsp;未执行命令：磁盘空间不足。&nbsp;<br>500&nbsp;格式错误，无法识别命令。&nbsp;<br>501&nbsp;参数语法错误。&nbsp;<br>502&nbsp;命令执行失败。&nbsp;<br>503&nbsp;命令顺序错误。&nbsp;<br>504&nbsp;命令所接的参数不正确。&nbsp;<br>530&nbsp;未登入。&nbsp;<br>532&nbsp;储存文件需要账户登入。&nbsp;<br>550&nbsp;未执行请求的操作。&nbsp;<br>551&nbsp;请求的命令终止，类型未知。&nbsp;<br>552&nbsp;请求的文件终止，储存位溢出。&nbsp;<br>553&nbsp;未执行请求的的命令，名称不正确。<img src ="http://www.cppblog.com/mydriverc/aggbug/109709.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2010-03-14 23:56 <a href="http://www.cppblog.com/mydriverc/archive/2010/03/14/109709.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>快速建立简单vsftp </title><link>http://www.cppblog.com/mydriverc/archive/2010/03/14/109694.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Sun, 14 Mar 2010 12:37:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2010/03/14/109694.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/109694.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2010/03/14/109694.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/109694.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/109694.html</trackback:ping><description><![CDATA[<p>今天一公司合作家伙说要传文件给我们这，就一文本文件非要求俺给他开个ftp,都没则了，只能给开个，从来没开过，在网络上搜索了下linux下开ftp可以用自带的vsftp也可以用软件建一个，而且听说vsftp也挺不错，就按网络教程一步步来了，这里主要是总结下自己的做法，毕竟不是每个人在要急用时候还去看一些文章的详解。<br>1.先用这几个命令看看是不是vsftpd安装正常<br>#service
vsftpd start 启动 <br>#service vsftpd stop 停止<br>#service vsftpd restart 重启<font face="Courier New"><font face="Courier New"><br>2.以上没有问题的话编辑vsftpd的配置文件<br>[root@localhost /]# </font>vi
/etc/vsftpd/vsftpd.conf&nbsp;&nbsp; //这个文件的具体内容解释可以看下面&#8220;参考文章&#8221;第一个链接<br>3.<font face="Courier New">anonymous_enable=YES 改成NO #禁止匿名访问</font><br>4.在 vsftpd.conf
中找到 <font face="Courier New">chroot_list_file=/etc/vsftpd.chroot_list把注释去掉然后建立<br></font></font>/etc/vsftpd.chroot_list文件，在文件中输入linux系统中的一个或多个用户名(一行一个)。<br><br>注：这个用户名是linux系统中root用户添加的。<br>[root@localhost
/]# useradd -s /sbin/nologin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//这样限制用户不能使用ssh登录<br><br>5.更改ftp端口仍然在vsftpd.conf文件中：<br><font face="Courier New">tcp_wrappers=YES<br>listen_port=2121&nbsp;&nbsp;
//自定义端口号，记得不要与已有端口冲突<br>local_root=/server/apache/htdocs&nbsp;
//设定用户explorer连接ftp时候显示的目录<br></font>保存退出编辑。<br><br>6.<br>#service vsftpd
restart 重启.然后一个利用系统已有用户名登录的ftp就开通了，<br>注：#service vsftpd start
命令只是在linux开启后手动开启vsftpd的命令，如果linux重启，还要使用该命令重新启动。<br>要想开机启动vsftp服务：执行chkconfig
--level 35 vsftpd on&nbsp;
(网络查询的未实践过)<br><br>后记：<br>如果有时间研究就多看看建立虚拟用户那部分，虚拟用户相比系统用户也许会更安全些，也稍微复杂些。<br><br>引用建立虚拟用户：<br>=====================================================</p>
<p><font size="2">[root@server root]# useradd vuser #新建一个虚拟登陆指定的号!<br>[root@server
root]# vi users.txt&nbsp; #虚拟号范本一行用户名下一行密码<br>[root@server root]# db_load -T -t hash
-f users.txt /etc/vsftpd.login.db #把users.txt的内容加为虚拟用户的帐号和密码<br>[root@server
root]# chmod 600 /etc/vsftpd.login.db #为了安全修改里面的内容<br>[root@server root]# vi
/etc/pam.d/ftp&nbsp; #修改里面的内容,使之与下面的相同<br>[root@server root]# more
/etc/pam.d/ftp<br>#%PAM-1.0<br>#auth&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; required&nbsp;&nbsp;&nbsp;
/lib/security/pam_listfile.so item=user sense=allow file<br>=/etc/ftpusers
onerr=succeed<br>#auth&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; required&nbsp;&nbsp;&nbsp; /lib/security/pam_pwdb.so shadow
nullok<br>#auth&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; required&nbsp;&nbsp;&nbsp; /lib/security/pam_shells.so<br>#account&nbsp;&nbsp;&nbsp;
required&nbsp;&nbsp;&nbsp; /lib/security/pam_pwdb.so<br>#session&nbsp;&nbsp;&nbsp; required&nbsp;&nbsp;&nbsp;
/lib/security/pam_pwdb.so<br>auth&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; required&nbsp;&nbsp;&nbsp; pam_userdb.so
db=/etc/vsftpd.login<br>account&nbsp;&nbsp;&nbsp;&nbsp; required&nbsp;&nbsp;&nbsp; pam_userdb.so
db=/etc/vsftpd.login<br>再次修改/etc/vsftpd.conf,使其内容与anonymous有关的全部禁用,还有刚才的chroot也被列为禁用,如果想用的话保证虚拟号能常的前提下再另行测试,并在最后加入二句话:</font></p>
<p><font size="2">guest_enable=YES</font></p>
<p><font size="2">guest_username=vuser&nbsp; 接下来就是重启vsftpd</font></p>
<p><font size="2">[root@server root]# killall -HUP vsftpd&nbsp; #!<br>[root@server
root]# ftp localhost&nbsp; #测试<br>Connected to server.redhat.org.cn.<br>220 Welcome
to linfeng's ftp server.<br>530 Please login with USER and PASS.<br>530 Please
login with USER and PASS.<br>KERBEROS_V4 rejected as an authentication
type<br>Name (localhost:root): tom&nbsp;&nbsp; #虚拟号<br>331 Please specify the
password.<br>Password:&nbsp;&nbsp; #虚拟号tom的密码<br>230 Login successful.&nbsp; #成功<br>Remote
system type is UNIX.<br>Using binary mode to transfer files.<br>ftp&gt;
ls<br>227 Entering Passive Mode (127,0,0,1,136,56)<br>150 Here comes the
directory listing.<br>226 Transfer done (but failed to open directory).&nbsp;&nbsp;
#怎么会禁止了呢?想一下上面的,,呵呵,这就是因为vuser用户的权限啊,只需"chmod o+r
/home/vuser"那可浏览,但不可上传,因为没有"w"位<br></font></p>
<p>=====================================<br><br>网络参考文章：<br><font face="Courier New">http://www.bianceng.cn/OS/Linux/200706/3020.htm</font><br><font face="Courier New">http://www.shineblog.com/user2/24790/archives/2005/175940.shtml</font><br>这两篇都比较详细。</p><img src ="http://www.cppblog.com/mydriverc/aggbug/109694.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2010-03-14 20:37 <a href="http://www.cppblog.com/mydriverc/archive/2010/03/14/109694.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>wu -ftp 安装和配置</title><link>http://www.cppblog.com/mydriverc/archive/2010/03/14/109686.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Sun, 14 Mar 2010 08:58:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2010/03/14/109686.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/109686.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2010/03/14/109686.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/109686.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/109686.html</trackback:ping><description><![CDATA[如何配置WU-FTP服务器 <br>本文出自: 作者: (2001-06-27 08:10:01) <br>&nbsp; &nbsp; 在众多的网络应用中，FTP（File
Transfer porotocol）有着非常重要的地位。在Internet中一 <br>&nbsp; &nbsp;
个十分重要的资源就是软件资源。而各种各样的软件资源大多数都是放在FTP服务器中的。可以说， <br>&nbsp; &nbsp;
FTP与WEB服务几乎占据了整个Internet应用的80%以上。 <br>&nbsp; &nbsp;
FTP服务可以根据服务对象的不同分为两类：一类是系统FTP服务器，它只允许系统上的合法用户使用； <br>&nbsp; &nbsp; 另一类是匿名FTP服务器，Anonymous
FTP Server，它使用任何人都可以登录到FTP服务器上去获取文件。 <br>一、选择和安装FTP服务器软件 <br>&nbsp; &nbsp;
如果你在安装LINUX系统的时候，在选择启动进程的时候选择了&#8220;ftpd&#8221;这一项的话，安装完LINUX系统后， <br>&nbsp; &nbsp;
它已经将一个默认的FTP服务器安装到系统中去了。我们已经可以利用它来实现系统FTP服务器的功能了。 <br>&nbsp; &nbsp;
我们只需在此基础上根据我们的需要进行一些个性化设定就可以了。 <br>&nbsp; &nbsp; 在绝大多数的LINUX发行版本中都选用的是WashingtonUniversity
FTP，它是一个著名的FTP服务器软件， <br>&nbsp; &nbsp; 一般简称为wu-ftp。它功能强大，能够很好地运行于众多的UNIX操作系统，例如：IBM
AIX、FreeBSD、 <br>&nbsp; &nbsp;
HP-UX、NeXTstep、Dynix、SunOS、Solaris等。所以Internet上的FTP服务器，一大半以上采用了它。 <br>&nbsp; &nbsp;
wu-ftp拥有许多强大的功能，很适于吞吐量较大的FTP服务器的管理要求： <br>&nbsp; &nbsp; 1） 可以在用户下载文件的同时对文件做自动的 <br>&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;压缩或解压缩操作； <br>&nbsp; &nbsp; 2） 可以对不同网络上的机器做不同的存取限制； <br>&nbsp; &nbsp; 3） 可以记录文件上载和下载时间； <br>&nbsp; &nbsp;
4） 可以显示传输时的相关信息，方便用户及时了 <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;解目前的传输动态； <br>&nbsp; &nbsp; 5） 可以设置最大连接数，提高了效率，有效地控
<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;制了负载。 <br>二、wu-ftp的组成 <br>&nbsp; &nbsp; 安装了wu-ftp后，你将在/bin目录下看到以下五个可执行文件：
<br>ftpd&nbsp; &nbsp;&nbsp; &nbsp; FTP服务器程序 <br>ftpshut&nbsp; &nbsp; 用于关闭FTP服务器程序 <br>ftpcount&nbsp;
&nbsp;显示目前在线人数&nbsp;&nbsp;<br>ftpwho&nbsp; &nbsp; 查看目前FTP服务器的连接情况 <br>ckconfig&nbsp; &nbsp;检查FTP服务器的设置是否正确 <br>&nbsp; &nbsp;
除了这些可执行文件以外，它还在/etc和/var目录下生成了七个配置文件： <br>/etc/ftpusers <br>/etc/ftpaccess
<br>/var/run/ftp.pids <br>/etc/ftpconversions <br>/var/log/xferlog
<br>/etc/ftpgroups <br>/etc/ftphosts <br>&nbsp; &nbsp;
系统安装了wu-ftp后，会建立一个特殊的用户ftp，并在/home目录下建立了一个ftpd目录，当用户以匿名 <br>&nbsp; &nbsp;
登录上来时，将会自动定位于这个目录下。在这个目录下一般会建立几个子目录。 <br>/home/ftpd/bin&nbsp; &nbsp; 存放一些供FTP用户使用的可 <br>&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;执行文件 <br>/home/ftpd/etc&nbsp; &nbsp; 存放一些供FTP用户使用的配置 <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;文件 <br>/home/ftpd/pub&nbsp; &nbsp; 存放供下载的信息 <br>/home/ftpd/incoming&nbsp; &nbsp; 存放供上载信息的空间
<br>三、wu-ftp的配置 <br>1. 查看、修改/etc/inetd.conf文件 <br>&nbsp; &nbsp;
/etc/inetd.conf文件是LINUX系统的超级服务器inetd的配置文件。它负责监听多个TCP/IP端口。当它收到 <br>&nbsp; &nbsp;
请求，就根据配置文件派生一个相应的服务器。通过使用超级服务器，其他服务就可以只在需要时才派生， <br>&nbsp; &nbsp;
从而大大节省了系统资源。而wu-ftp就是利用超极服务器inetd来监听请求的。当超级服务器inetd收到了客 <br>&nbsp; &nbsp;
户端的FTP请求时，就根据配置文件打开一个FTP服务进程。所以我们如果要使用wu-ftp，就必须确认在超级 <br>&nbsp; &nbsp;
服务器inetd的配置文件inetd.conf中有这样一句： <br>ftp stream tcp nowait root /usr/sbin/tcpd
wu.ftpd <br>以便当超级服务器收到FTP请求的时候，能够派生一个wu-ftp的FTP服务进程。（注：要确认是否有这样一行时，
<br>可以使用文件内容查找命令来确认： <br>cat /etc/inetd.conf | grep ftp&nbsp;&nbsp;<br>如果没有，则用手工加入或手工修改。
<br>2. wu-ftpd的命令选项 <br>&nbsp; &nbsp;
wu-ftpd就是wu-ftp的服务进程。它可以不带参数执行，也可以带参数执行。下面简单介绍一下wu-ftpd的执 <br>&nbsp; &nbsp; 行参数。
<br>-d&nbsp;&nbsp;当FTP服务器出错时，将错误入系统的syslog中； <br>-l&nbsp;&nbsp;将每次FTP客户端进行连接的入系统的syslog中；
<br>-t&nbsp;&nbsp;设置FTP客户端连接几分钟无操作就切断连接； <br>-a&nbsp;&nbsp;使wu-ftp使用/etc/ftpaccess的设定；
<br>-A&nbsp;&nbsp;使wu-ftp不使用/etc/ftpaccess的设定； <br>-L&nbsp;&nbsp;将FTP客户端连线后所执行的程序记录在系统的 <br>&nbsp; &nbsp;
syslog中； <br>-I&nbsp;&nbsp;将FTP客户端上载文件的日志记录在/usr/adm.xferlog文件中； <br>-o&nbsp;&nbsp;将FTP客户端下载文件的日志记录
<br>&nbsp; &nbsp; 在/usr/adm/xferlog文件中。 <br>&nbsp; &nbsp; 通过对以上参数的理解，我们建议，将上面系统安装时的那条默认配置改为： <br>ftp
stream tcp nowait root /usr/sbin/tcpd wu.ftpd &#8211;a &#8211;I&nbsp;&nbsp;<br>3.提供自动压缩、解压缩的功能 <br>&nbsp; &nbsp;
如果想让FTP服务器有自动压缩、解压缩的功能，必须先将一些压缩、解压缩的命令文件如tar、gzip、 <br>&nbsp; &nbsp;
gunzip、compress、uncompress等命令文件拷贝到/home/ftpd/bin目录下。 <br>4. 关于/etc/ftpaccess的设置
<br>&nbsp; &nbsp; 这个配置文件是FTP服务器上最重要的配置文件，它直接关系到你的FTP服务器能否正常工作，还有许多权 <br>&nbsp; &nbsp;
限上的设置。下面是一个典型的配置实例。 <br>loginfails 3 <br>class&nbsp;&nbsp;local&nbsp; &nbsp; real&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;*
<br>class&nbsp;&nbsp;remote&nbsp;&nbsp;anonymous guest&nbsp;&nbsp;*
<br>limit&nbsp;&nbsp;remote&nbsp;&nbsp;100&nbsp;&nbsp;Any&nbsp;&nbsp;/etc/ftpd/toomany.msg
<br>message&nbsp;&nbsp;/etc/ftpd/welcome.msg&nbsp;&nbsp;login <br>compress&nbsp;&nbsp;yes&nbsp;&nbsp;local remote
<br>tar&nbsp;&nbsp;yes&nbsp;&nbsp;local remote <br>private&nbsp;&nbsp;yes <br>passwd-check&nbsp;&nbsp;rfc822&nbsp;&nbsp;warn
<br>log commands&nbsp;&nbsp;real <br>log transfer&nbsp;&nbsp;anonymous guest&nbsp;&nbsp;inbound outbound
<br>log transfer&nbsp;&nbsp;real&nbsp;&nbsp;inbound <br>shutdown&nbsp;&nbsp;/etc/ftpd/shut.msg
<br>delete&nbsp;&nbsp;no&nbsp;&nbsp;anonymous,guest <br>overwrite&nbsp;&nbsp;no&nbsp;&nbsp;anonymous,guest
<br>rename&nbsp;&nbsp;no&nbsp;&nbsp;anonymous <br>chmod&nbsp;&nbsp;no&nbsp;&nbsp;anonymous,guest
<br>umask&nbsp;&nbsp;no&nbsp;&nbsp;anonymous <br>upload&nbsp;&nbsp;/home/ftpd&nbsp;&nbsp;*&nbsp;&nbsp;no
<br>upload&nbsp;&nbsp;/home/ftpd&nbsp;&nbsp;/bin&nbsp;&nbsp;no <br>upload&nbsp;&nbsp;/home/ftpd&nbsp;&nbsp;/etc&nbsp;&nbsp;no
<br>upload&nbsp;&nbsp;/home/ftpd&nbsp;&nbsp;/pub&nbsp;&nbsp;yes&nbsp;&nbsp;real&nbsp;&nbsp;0644 dirs
<br>upload&nbsp;&nbsp;/home/ftpd&nbsp;&nbsp;/incoming&nbsp;&nbsp;yes&nbsp;&nbsp;real guest anonymous 0644 dirs
<br>alias&nbsp;&nbsp;in&nbsp;&nbsp;/incoming <br>email&nbsp;&nbsp;<br><a  href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#103;&#117;&#101;&#115;&#116;&#64;&#120;&#120;&#120;&#46;&#110;&#101;&#116;">guest@xxx.net</a><br><br>email&nbsp;&nbsp;<br><a  href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#103;&#117;&#101;&#115;&#116;&#64;&#121;&#121;&#121;&#46;&#110;&#101;&#116;">guest@yyy.net</a><br><br>deny&nbsp;&nbsp;*.com.tw&nbsp;&nbsp;/etc/ftpd/deny.msg
<br>&nbsp; &nbsp; 下面我们逐句进行讲解，并给出每条设置的含义，以便大家触类旁通，以便根据自己FTP服务器的具体 <br>&nbsp; &nbsp; 情况进行合理的设置。 <br>1．
格式：loginfails&nbsp;&nbsp;[次数] <br>&nbsp; &nbsp;功能：设定当用户登录到FTP服务器时，允许用户输错密码的次数。 <br>&nbsp; &nbsp;实例：loginfails
3：密码输入错误三次就切断连接。 <br>2． 格式：class&nbsp;&nbsp;[类名]&nbsp;&nbsp;[real/guest/anonymous]&nbsp;&nbsp;[IP地址] <br>&nbsp;
&nbsp;功能：这个指令的功能设定FTP服务器上用户的类别。并可对客户端的IP地址进行限制，允许某部分的 <br>&nbsp;
&nbsp;IP地址或全部的IP地址访问。而在FTP服务器上的用户基本上可以分为以下三类： <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;real&nbsp;&nbsp;在该FTP服务器有合法帐号的用户；
<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;guest&nbsp;&nbsp;有记录的匿名用户； <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;anonymous&nbsp;&nbsp;权限最低的匿名用户 <br>&nbsp;
&nbsp;实例：class&nbsp;&nbsp;local&nbsp;&nbsp;real&nbsp;&nbsp;*：定义一个名为local的类，它包含了在任何地方登录(*代表所有IP地址） <br>&nbsp; &nbsp;的real用户。
<br>&nbsp; &nbsp;&nbsp; &nbsp;class&nbsp;&nbsp;remote&nbsp;&nbsp;anonymous guest&nbsp;&nbsp;*:定义一个名为remote的类，它包含了在任何地方登录的anonymous
<br>&nbsp; &nbsp;&nbsp; &nbsp;用户和guest用户。 <br>3． 格式：limit&nbsp;&nbsp;[类别]&nbsp;&nbsp;[人数]&nbsp;&nbsp;[时间]&nbsp;&nbsp;[文件名] <br>&nbsp;
&nbsp;功能：这个指令的功能为设置指定的时间内指定的类别允许连接的指定人数上限。当达到人数上限的时候， <br>&nbsp; &nbsp;显示指定文件的内容。 <br>&nbsp; &nbsp;&nbsp; &nbsp;
实例：limit&nbsp;&nbsp;remote&nbsp;&nbsp;100&nbsp;&nbsp;Any&nbsp;&nbsp;/etc/ftpd/toomany.msg：在任何时间内，remote类的访问用户达 <br>&nbsp; &nbsp;&nbsp;
&nbsp; 到100人时，将不再允许无法产生新的连接，当第101位客户要连接时，连接将失败，并象用户出示文 <br>&nbsp; &nbsp;&nbsp; &nbsp;
件/etc/ftpd/toomany.msg的内容。 <br>4． 格式：message&nbsp;&nbsp;[文件名称]&nbsp;&nbsp;[指令]&nbsp;&nbsp;<br>&nbsp;
&nbsp;功能：当用户执行所指定的指令时，系统将指定的文件内容显示出来。
<br>实例：message&nbsp;&nbsp;/etc/ftpd/welcome.msg&nbsp;&nbsp;login：当用户执行login命令时，也就是登录到FTP服务器上的时候，
<br>系统将显示文件/etc/ftpd/welcome.msg的内容。 <br>5． 格式：compress&nbsp;&nbsp;[yes/no]&nbsp;&nbsp;[类别]&nbsp;&nbsp;<br>&nbsp;
&nbsp;功能：设置哪一个类别的用户可以使用compress（压缩）功能。 <br>&nbsp;&nbsp;实例：compress&nbsp;&nbsp;yes&nbsp;&nbsp;local
remote：允许local和remote两个类别的用户都能使用&nbsp; &nbsp;&nbsp; &nbsp;compress(压缩)功能。 <br>6．
格式：tar&nbsp;&nbsp;[yes/no]&nbsp;&nbsp;[类别]&nbsp;&nbsp;<br>&nbsp; &nbsp;功能：设置哪一个类别的用户可以使用tar（归档）功能。 <br>&nbsp; &nbsp;&nbsp; &nbsp;
实例：tar&nbsp;&nbsp;yes&nbsp;&nbsp;local remote：允许local和remote两类的用户都能使用tar功能。 <br>7．
格式：private&nbsp;&nbsp;[yes/no]&nbsp;&nbsp;<br>&nbsp; &nbsp;功能：设定是否支持群组对文件的取用。 <br>&nbsp;
&nbsp;实例：private&nbsp;&nbsp;yes：支持群组对文件的取用。 <br>8．
格式：passwd-check&nbsp;&nbsp;[none/trivial/rfc822]&nbsp;&nbsp;[enforce/warn] <br>&nbsp;
&nbsp;功能：设定对匿名用户anonymous的密码使用方式。 <br>&nbsp;&nbsp;none&nbsp; &nbsp;表示不做密码验证，任何密码都可以登录； <br>trival&nbsp;
&nbsp;表示只要输入的密码中含有字符&#8220;@&#8221;就可以登录； <br>rfc822&nbsp;&nbsp;表示密码一定要符合RFC822中所规定的E-Mail格式才能登录；
<br>enfore&nbsp;&nbsp;表示输入的密码不符合以上指定的格式就不让登录； <br>warn&nbsp; &nbsp;表示密码不符合规定时只出现警告信息，仍然能够登录。
<br>&nbsp;&nbsp;实例：passwd-check&nbsp;&nbsp;rfc822&nbsp;&nbsp;warn：希望能够得到符合规定的E-Mail作为密码，但如果不是，也允许登录。 <br>9．
格式：log command [real/guest/anonymous]&nbsp;&nbsp;<br>&nbsp; &nbsp;
功能：设置哪些用户登录后的操作记录在文件/usr/adm/xferlog中。 <br>&nbsp; &nbsp; 实例：log command
real：当real用户登录后，将他的操作记录下来。由于其它用户权限较低，所以操作不 <br>&nbsp; &nbsp; 会引起太大的安全隐患，所以一般只需记下real用
<br>户的操作就可以了。 <br>10． 格式：log
transfers&nbsp;&nbsp;[real/guest/anonymous]&nbsp;&nbsp;[inbound/outbound] <br>&nbsp;
&nbsp;功能：设置哪些用户的上载（inbound）和下载（outbound）操作做日志。 <br>&nbsp; &nbsp;实例：log transfer&nbsp;&nbsp;anonymous
guest&nbsp;&nbsp;inbound outbound：对于匿名用户要更加的关注它们的文件操作， <br>&nbsp; &nbsp;所以无论上载、下载都进行记录。 <br>&nbsp;&nbsp;log
transfer&nbsp;&nbsp;real&nbsp;&nbsp;inbound：对于合法用户则只记录他的上载记录。 <br>11． 格式：shutdown&nbsp;&nbsp;[文件名] <br>&nbsp;
&nbsp;功能：FTP服务器关闭的时间可以设置在后面所指定的文件中，当设置的时间一到，便无法登录FTP服务器了， <br>&nbsp;
&nbsp;要恢复的话只有将这个文件删掉。而这个文件必 须由指令/bin/ftpshut来生成。 <br>&nbsp; &nbsp;&nbsp; &nbsp;
实例：shutdown&nbsp;&nbsp;/etc/ftpd/shut.msg <br>12．
格式：delete&nbsp;&nbsp;[yes/no]&nbsp;&nbsp;[real/anonymous/guest] <br>&nbsp;
&nbsp;功能：设置是否允许指定用户使用delete命令删除文件。默认是允许。 <br>&nbsp;
&nbsp;实例：delete&nbsp;&nbsp;no&nbsp;&nbsp;anonymous,guest：为了更好地管理FTP服务器，一般情况下，我们不允许匿名用户执行 <br>&nbsp; &nbsp;delete命令。
<br>13． 格式：overwrite&nbsp;&nbsp;[yes/no]&nbsp;&nbsp;[real/anonymous/guest] <br>&nbsp;
&nbsp;功能：设置是否允许指定用户覆盖同名文件。默认是允许。 <br>&nbsp;
&nbsp;实例：overwrite&nbsp;&nbsp;no&nbsp;&nbsp;anonymous,guest：为了更好地管理FTP服务器，一般情况下，我们不允许匿名用户覆 <br>&nbsp; &nbsp;盖同名文件。
<br>14． 格式：rename&nbsp;&nbsp;[yes/no]&nbsp;&nbsp;[real/anonymous/guest] <br>&nbsp;
&nbsp;功能：设置是否允许指定用户使用rename命令来为文件改名。默认是允许。 <br>&nbsp;
&nbsp;实例：delete&nbsp;&nbsp;no&nbsp;&nbsp;anonymous：为了更好地管理FTP服务器，一般情况下，我们不允许匿名用户执行rename命 <br>&nbsp;
&nbsp;令改变文件名。而对有记录的匿名用户则适当的放宽，允许他们使用改名命令。 <br>15．
格式：chmod&nbsp;&nbsp;[yes/no]&nbsp;&nbsp;[real/anonymous/guest] <br>&nbsp;
&nbsp;功能：设置是否允许指定用户使用chmod命令更改文件权限。默认是允许。 <br>&nbsp;
&nbsp;实例：delete&nbsp;&nbsp;no&nbsp;&nbsp;anonymous，guest：为了更好地管理FTP服务器，一般情况下，我们不允许匿名用户执行 <br>&nbsp;
&nbsp;chmod命令更改文件权限。 <br>16． 格式：umask&nbsp;&nbsp;[yes/no]&nbsp;&nbsp;[real/anonymous/guest] <br>&nbsp;
&nbsp;功能：设置是否允许指定用户使用umask命令。默认是允许。 <br>&nbsp;
&nbsp;实例：delete&nbsp;&nbsp;no&nbsp;&nbsp;anonymous：为了更好地管理FTP服务器，一般情况下，我们不允许匿名用户执行umask命令。 <br>17．
格式：upload&nbsp;&nbsp;[根目录]&nbsp;&nbsp;[上载目录]&nbsp;&nbsp;[yes/no]&nbsp;&nbsp;[用户]&nbsp;&nbsp;[权限]&nbsp;&nbsp;[dirs/nodirs] <br>&nbsp;
&nbsp;功能：对可以上载的目录进行更加详细的设置。 <br>&nbsp;
&nbsp;实例：upload&nbsp;&nbsp;/home/ftpd&nbsp;&nbsp;*&nbsp;&nbsp;no：表示在子目录/home/ftpd下不允许上载； <br>&nbsp;
&nbsp;upload&nbsp;&nbsp;/home/ftpd&nbsp;&nbsp;/bin&nbsp;&nbsp;no：表示在子目录/home/ftpd/bin下不允许上载； <br>&nbsp;
&nbsp;upload&nbsp;&nbsp;/home/ftpd&nbsp;&nbsp;/etc&nbsp;&nbsp;no：表示在子目录/home/ftpd/etc下不允许上载； <br>&nbsp;
&nbsp;upload&nbsp;&nbsp;/home/ftpd&nbsp;&nbsp;/pub&nbsp;&nbsp;yes&nbsp;&nbsp;real&nbsp;&nbsp;0644 dirs：允许用服务器上的合法用户在子目录/home/ftpd/pub目录
<br>&nbsp; &nbsp;下能上载权限为0644(也就是-rw-r--r--)的文件，而且在这个目录下可以新建子目录。
<br>&nbsp;&nbsp;upload&nbsp;&nbsp;/home/ftpd&nbsp;&nbsp;/incoming&nbsp;&nbsp;yes&nbsp;&nbsp;real guest anonymous 0644
dirs：允许所有的用户在子目录 <br>&nbsp;&nbsp;/home/ftpd/incoming下能上载权限为0644的文件，而且在这个目录下可以新建子目录。
<br>18． 格式：alias&nbsp;&nbsp;[目录别名]&nbsp;&nbsp;[目录名] <br>&nbsp; &nbsp;功能：给指定目录设置一个别名，在切换目录时就可以使用较短的目录别名。 <br>&nbsp;
&nbsp;实例：alias&nbsp;&nbsp;inc： /incoming：为子目录incoming设置一个别名inc：。 <br>19．
格式：email&nbsp;&nbsp;[guest的E-Mail地址] <br>&nbsp;
&nbsp;功能：只要将某些E-Mail地址设置在这个地方，那么这些用户登录到FTP服务器时，他的身份将为guest，一般权 <br>&nbsp;
&nbsp;限比real低一些，比anonymous高。 <br>&nbsp; &nbsp;实例：email <br><a  href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#103;&#117;&#101;&#115;&#116;&#64;&#120;&#120;&#120;&#46;&#110;&#101;&#116;">guest@xxx.net</a><br>&nbsp; &nbsp;email <br><a  href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#103;&#117;&#101;&#115;&#116;&#64;&#121;&#121;&#121;&#46;&#110;&#101;&#116;">guest@yyy.net</a><br>：这里仅是一个示例，实际上可&nbsp; &nbsp;&nbsp;&nbsp;以包含多个符合规范
<br>&nbsp; &nbsp;的E-Mail地址。 <br>20． 格式：deny&nbsp;&nbsp;[IP地址/域名]&nbsp;&nbsp;[说明文件] <br>&nbsp;
&nbsp;功能：这个设置可以限制哪一些IP地址或域名的用户无法登入FTP服务器。 <br>&nbsp;
&nbsp;实例：deny&nbsp;&nbsp;*.com.tw&nbsp;&nbsp;/etc/ftpd/deny.msg：设置凡是域名是以&#8220;.com.tw&#8221;结束的域名，都禁止其访问。 <br>&nbsp;
&nbsp;而将/etc/ftpd/deny.msg的内容显示给用户看。 <br>5. 设置/etc/ftpuser,禁止某些用户登录 <br>&nbsp; &nbsp;
有时我们需要禁止一些用户使用FTP服务。其实这个设置是十分简单的，只需要将要禁止的用户帐号写入文件 <br>&nbsp; &nbsp;
/etc/ftpuser中。由于从系统的安全考虑，一般我们是不希望权限过大的用户和一些与命令名相同的用户进入 <br>&nbsp; &nbsp;
FTP服务器。所以在缺省的配置中，一般以下用户已经被列入了&#8220;黑名单&#8221;。 <br>&nbsp;&nbsp;root&nbsp; &nbsp;<br>&nbsp;&nbsp;uucp <br>&nbsp;&nbsp;news <br>&nbsp;&nbsp;bin
<br>&nbsp;&nbsp;adm <br>&nbsp;&nbsp;nobody <br>&nbsp;&nbsp;lp <br>&nbsp;&nbsp;sync <br>&nbsp;&nbsp;shutdown <br>&nbsp;&nbsp;halt <br>&nbsp;&nbsp;mail&nbsp;
&nbsp;<br>6. 设置/etc/ftphosts,禁止某些来自指定机器上的登录如果你需要拒绝来自某些主机的登录，一种方法就是在
<br>/etc/ftpaccess中设置deny命令，另一种更加简单的方法就是在/etc/ftphosts中写入你要禁止的主机的IP地址或域名。 <br>7.
使新的配置生效 <br>到此为止，我们已经能够根据自己的需要对FTP服务器配置进行必要的修改和调整。而让我们重新配置后，就必须使其
<br>生效。一般的，对/etc/ftpaccess的配置是直接作用于设置后的下一次FTP服务进程。而其它的则要对inetd进程重新 <br>启动。
<br>5.4 wu-ftp相关的其他一些命令的使用 <br>5.4.1 连接数统计命令ftpcount
<br>我们可以使用ftpcount命令十分清楚地统计出当前连接到FTP服务器上的用户数目，并且同时列出上限。命令输出 <br>如下所示：
<br>Service class local&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;0&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Users(20maximum) <br>Service class
remote&nbsp; &nbsp;&nbsp; &nbsp; 5&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Users(100maximum) <br>5.4.2 在线用户查看命令ftpwho
<br>我们可以使用ftpwho命令十分清楚地列出当前连接的用户的详细情况。 <br>5.4.2 FTP关闭文件生成命令ftpshut
<br>我们可以使用ftpshut命令生成一个在/etc/ftpaccess中设置的shut.msg文件，用于关机设定。ftpshut命令的格式为：
<br>Ftpshut&nbsp; &nbsp;&nbsp; &nbsp;time&nbsp; &nbsp;<br>-l&nbsp; &nbsp;这个参数设定在关闭FTP服务器功能前多少分钟时停止用户的连接； <br>-d&nbsp;
&nbsp;这个参数设定在关闭FTP服务器功能前多少分钟时切断用户连接； <br>time
指定关闭FTP服务器的时间。例如6：20分则写为0620；&nbsp;&nbsp;<br>(<br><a  href="http://www.fanqiang.com/" target="_blank">http://www.fanqiang.com</a><br>)&nbsp; &nbsp;&nbsp;&nbsp;进入【UNIX论坛】&nbsp; <br><img src ="http://www.cppblog.com/mydriverc/aggbug/109686.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2010-03-14 16:58 <a href="http://www.cppblog.com/mydriverc/archive/2010/03/14/109686.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VSFTPD官方资料翻译版（不完整版）---</title><link>http://www.cppblog.com/mydriverc/archive/2010/03/14/109685.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Sun, 14 Mar 2010 08:55:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2010/03/14/109685.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/109685.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2010/03/14/109685.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/109685.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/109685.html</trackback:ping><description><![CDATA[<font face="幼圆">翻译了部分VSFTPD的官方资料。<br>有些知道是什么意思，但难于翻译。有些涉及专业的知识，我自己也不懂，只好按字面翻译。有些我自己看不懂，只好尽量翻译。<br>如果看了其中一部分觉得糊涂，请参阅官方文挡。<br>安装篇
<br>=============== <br>这个文件详细介绍了如何从VSFTPD的.tar.gz分发包开始，建立和安装并运行VSFTPD。
<br><br><font color="fuchsia">1</font><font color="fuchsia">）建立VSFTPD
</font><br>先进入解压.tar.gz文件后产生的目录内。如下： <br>cd vsftpd-2.0.1
<br><br>编辑"builddefs.h"以操作compile-time设定。（tcp_wrappers
build,等）<br>输入make,回车（如果它不工作请发邮件通知我 . <br>这将产生一个二进制文件，你可以验证一下。如下：
<br>[chris@localhost vsftpd]$ ls -l vsftpd <br>-rwxrwxr-x 1 chris chris 61748
Sep 27 00:26 vsftpd <br><br><font color="fuchsia">2</font><font color="fuchsia">）满足VSFTPD安装所需的一些条件
</font><br>VSFTPD默认设置需要一个"nobody"用户，如果这个用户不存在，那么添加它。如下： <br>[root@localhost
root]# useradd nobody <br>useradd: user nobody exists
<br><br>VSFTPD默认设置需要一个空目录：/usr/share/empty.增加这个目录，如果它还不存在的话。如下：
<br>[root@localhost root]# mkdir /usr/share/empty/ <br>mkdir: cannot create
directory `/usr/share/empty': File exists
<br><br>如果容许匿名用户（anonymous)，那么你将需要一个"ftp"用户和其home目录（这个home目录不属于&#8220;ftp&#8221;用户，而且&#8220;ftp"用户也对其没有写权限）在你的系统中存在。<br>以下命令用来创建一个"ftp"用户，如果它还不存在的话。
<br>[root@localhost root]# mkdir /var/ftp/ <br>[root@localhost root]# useradd -d
/var/ftp ftp <br><br>（即使你的"ftp"用户已经存在，完成以下这两步也是很有好处的：） <br>[root@localhost
root]# chown root.root /var/ftp <br>[root@localhost root]# chmod og-w /var/ftp
<br><br>3）安装VSFTPD的配置、执行和帮助文件。<br>输入"make
install"后会将二进制文件和帮助文件拷贝到适当的目录。<br>你也可以手工拷贝这些文件： <br>cp vsftpd
/usr/local/sbin/vsftpd <br>cp vsftpd.conf.5 /usr/local/man/man5 <br>cp vsftpd.8
/usr/local/man/man8 <br><br>"make install"不会拷贝默认的配置文件，所以建议你手工拷贝： <br>cp
vsftpd.conf /etc <br>daidong注：根据你系统版本的不同，也可能是 cp vsftpd.conf /etc/vsftpd
<br><br>4)测试 （无inetd影响）
<br>VSFTPD能运行在独立模式（standalone)或者通过inetd(xinetd)来启动。<br>你能通过inetd来运行vsftpd以更好地控制它。但我们在首次运行时不这么做，以便检查系统是否现在配置正常。<br>编辑/etc/vsftpd.conf（daidong注：也可能是/etc/vsftpd/vsftpd.conf)，并在最下面加入以下这一行：
<br><font color="#333399">listen=YES</font> <br><br>这将告诉VSFTPD不要从inetd启动。
<br>OK，现在试着启动FTP。<br>以ROOT登录。<br>确定你没有运行其他FTP服务（否则VSFTPD不能占用FTP所需的21端口）。<br>运行那个二进制文件，如下：
<br>[root@localhost root]# <font color="#333399">/usr/local/sbin/vsftpd &amp;
</font><br>[1] 2104 <br><br>如果一切正常，那么你将连上FTP服务器，如下： <br>[chris@localhost chris]$
ftp localhost <br>Connected to localhost (127.0.0.1). <br>220 (vsFTPd 1.1.1)
<br>Name (localhost:chris): ftp <br>331 Please specify the password.
<br>Password: <br>230 Login successful. Have fun. <br>Remote system type is
UNIX. <br>Using binary mode to transfer files. <br>ftp&gt; ls <br>227 Entering
Passive Mode (127,0,0,1,229,133) <br>150 Here comes the directory listing.
<br>d--x--x--x 2 0 0 4096 Jan 14 2002 bin <br>d--x--x--x 2 0 0 4096 Apr 21 20:52
etc <br>drwxr-xr-x 2 0 0 4096 Apr 21 20:52 lib <br>drwxr-sr-x 2 0 50 4096 Jul 26
22:58 pub <br>226 Directory send OK. <br>ftp&gt;
<br><br>5）从inetd或者类似方式启动（官方推荐使用standalone方式）<br>你也许想通过inetd或者类似方式启动VSFTPD，因为这能给你更多的感受。例如xinetd就有很多的设置。<br>（注意：VSFTPD的内在机制屏蔽了xinetd的大多数的有用的设置）。<br>如果使用标准的"inetd",你需要编辑/etc/inetd.conf,在其中加入以下一行：
<br>ftp stream tcp nowait root /usr/sbin/tcpd /usr/local/sbin/vsftpd
<br><br>（确定你删除或者注释掉一些已存在的FTP服务配置行。如果你没有安装tcp_wrappers,或者不想使用它们，那么请去掉/usr/sbin/tcpd
part). <br><br>inetd需要指定并重新载入它的配置文件： <br>kill -SIGHUP `pidof inetd`
<br><br>如果你想使用"xinetd",请参阅我们提供的范例 /EXAMPLE/INTERNET_SITE/README.
而其他范例文件将告诉你如何调配出更强大的xinetd功能。
<br><br>6）为本地登录配置PAM文件（可选）<br>如果你在一台激活了PAM的设备上运行VSFTPD，你需要提供一个 /etc/pam.d/ftp
文件。否则非匿名用户将无法登录服务器。<br>（注：如果你的PAM版本比较老，那么这个文件也许是 /etc/pam.conf).
<br><br>做为一个标准设置，你可以拷贝一个已提供的范例文件，如下： <br>cp RedHat/vsftpd.pam /etc/pam.d/ftp
<br><br>7）自定义你的配置文件<br>完成以上的配置后，建议你安装一个配置文件。默认的配置文件位置是/etc/vsftpd.conf.
在VSFTPD软件分发包内有一个范例配置文件。<br>你可以拷贝其为/etc/vsftpd.conf以做进一步修改。 <br>cp vsftpd.conf
/etc <br>（daidong注：也可能是 cp vsftpd.conf /etc/vsftpd ).
<br><br>这个默认配置即不容许本地登录也不容许匿名用户上传，也许你希望更改这个配置。<br>其它 <br>===================
<br>测试平台 （已通过） <br>-流行的，功能完善的平台都能测试通过。在以下平台的较新版本，VSFTPD工作得很好。在其大部分较早的版本下，也运行正常。
<br>- RedHat Linux <br>- RedHat Enterprise Linux <br>- Solaris / GNU tools
(Solaris 8 or newer) <br>- SuSE Linux <br>- Debian Linux <br>- OpenBSD <br>-
FreeBSD <br>- NetBSD <br>- HP-UX / GNU tools <br>- IRIX / GNU tools <br>- Mac OS
X (note; older versions have setgroups() problem. 10.3.4 reported OK) <br>虚拟用户1
<br>=============
<br>这个例子示范了如何为虚拟用户设置VSFTPD/PAM。<br>虚拟用户是一个在系统中并不作为一个登录实体而存在的用户。使用虚拟用户比使用真实的用户更安全，因为这个账号只能用于FTP服务器。<br>虚拟用户经常用来提供给不大可信任的用户访问某些资源，而这些资源通常是其他普通用户不能访问的。
<br><br><font color="red">1</font><font color="red">）创建虚拟用户数据库
</font><br>我们将使用pam_userdb来认证虚拟用户。这需要提供一个&#8220;db"格式（一种通用数据库格式）的用户名/密码文件。<br>创建一个"db"格式的文件，首先要创建一个标准文本文件，并把用户名，密码以竖直排列方式输入。如logins.txt：
<br>tom <br>foo <br>fired <br>bar <br>这个例子中,tom用户的密码是foo.fired用户的密码是bar.
<br>以ROOT登录，创建一个数据库文件，如下： <br>db_load -T -t hash -f logins.txt
/etc/vsftpd_login.db <br>（这要求berkeley db程序已经安装）
<br>(注：一些系统也许安装了多个版本的"db",所以某些情况下你可能使用"db3_load"才是正确的。对于一些
Debian系统就是这样。<br>关键在于要让pam_userdb相信它的登录数据库是哪一个db版本所产生（一般都是db3，尽管你的系统里可能安装的是db4).）<br>这将创建/etc/vsftpd_login.db文件。显然，你希望设定这个文件的权限：
<br>chmod 600 /etc/vsftpd_login.db <br><br>要了解更多关于维护你的登录数据库的信息，请在"berkeley
DB"察看相关文档： <br><a  href="http://www.sleepycat.com/docs/utility/index.html" target="_blank"><font color="#0000ff">http://www.sleepycat.com/docs/utility/index.html</font></a>
<br><br><font color="red">2</font><font color="red">）用你的新数据库创建一个PAM文件
</font><br>请参考范例vsftpd.pam，它包含2行： <br>auth required /lib/security/pam_userdb.so
db=/etc/vsftpd_login <br>account required /lib/security/pam_userdb.so
db=/etc/vsftpd_login <br><br>这是告诉PAM用新的数据库去验证用户。把这个PAM文件拷贝到PAM目录，一般是/etc/pam.d
<br>cp vsftpd.pam /etc/pam.d/ftp <br><br><font color="red">3)</font><font color="red">为虚拟用户设置home目录<br></font>useradd -d /home/ftpsite virtual <br>ls -ld
/home/ftpsite <br>(which should give): <br>drwx------ 3 virtual virtual 4096 Jul
30 00:39 /home/ftpsite <br><br>我们已经创建了一个名叫"virtual"的用户，home目录是"/home/ftpsite".
<br>我们拷贝一些东西到这个下载目录： <br>cp /etc/hosts /home/ftpsite <br>chown virtual.virtual
/home/ftpsite/hosts <br><br>4）创建你的vsftpd.conf配置文件<br>请参考这个目录下的例子。让我们一行行地看一看这些配置：
<br>anonymous_enable=NO <br>local_enable=YES
<br><br>安全起见，屏蔽了匿名用户，只启用了非匿名用户（即虚拟用户使用的账号） <br><br>write_enable=NO
<br>anon_upload_enable=NO <br>anon_mkdir_write_enable=NO
<br>anon_other_write_enable=NO <br><br>为了安全请确认这几个配置，这将关闭写的权限。
<br><br>chroot_local_user=YES <br><br>这将把虚拟用户锁定在我们在以上设置的/home/ftpsite目录内。
<br><br>guest_enable=YES <br>guest_username=virtual
<br><br>guest_enable非常重要-它激活了虚拟用户！而guest_username说明所有的虚拟用户都对应我们在上面设置的真实用户：&#8220;virtual".
<br>这同时确定了虚拟用户在文件系统中的位置，也就是说，虚拟用户的home目录即"virtual"用户的home目录：/home/ftpsite。
<br><br>listen=YES <br>listen_port=10021
<br><br>这让VSFTPD以独立模式(standalone)运行，而不是从inetd方式启动。也就是说，你运行VSFTPD可执行文件就启动了FTP服务。<br>同时也让VSFTPD启用非标准端口10021来监听FTP请求（FTP一般使用21端口）。
<br><br>pasv_min_port=30000 <br>pasv_max_port=30999
<br><br>这设定了被动模式的FTP请求端口。当你配置了一个防火墙的时候，这个配置就很好用。<br>拷贝范例配置文件到/etc <br>cp
vsftpd.conf /etc/ <br>(daidong注：也可能是/etc/vsftpd) <br><br>5)启动VSFTPD
<br>到VSFTPD二进制文件所在的目录，输入： <br>./vsftpd <br><br>如果一切正常，这个命令将生效。否则，你将会看到一些错误信息的反馈。
<br><br>6）测试<br>启动另一个会话。（或者ctrl-z，再输入"bg",让VSFTPD在后台运行）。<br>这是一个FTP会话的例子：
<br><br>ftp localhost 10021 <br>Connected to localhost (127.0.0.1). <br>220
ready, dude (vsFTPd 1.1.0: beat me, break me) <br>Name (localhost:chris): tom
<br>331 Please specify the password. <br>Password: <br>230 Login successful.
Have fun. <br>Remote system type is UNIX. <br>Using binary mode to transfer
files. <br>ftp&gt; pwd <br>257 "/" <br>ftp&gt; ls <br>227 Entering Passive Mode
(127,0,0,1,117,135) <br>150 Here comes the directory listing. <br>226 Transfer
done (but failed to open directory). <br>ftp&gt; size hosts <br>213 147
<br>ftp&gt; <br><br>注释：<br>密码是"foo" <br>出现&#8221;failed to open
directory&#8220;的话，别担心。这是因为/home/ftpsite目录不容许被任意浏览。<br>（我们可以更改anon_world_readable_only=NO以消除告警，但为了安全，还是保留这个配置）。<br>我们能通过size命令看到我们已经访问了被我们拷贝到这里的"hosts"文件。
<br><br>vsftpd.conf <br>anonymous_enable=NO <br>local_enable=YES
<br>write_enable=NO <br>anon_upload_enable=NO <br>anon_mkdir_write_enable=NO
<br>anon_other_write_enable=NO <br>chroot_local_user=YES <br>guest_enable=YES
<br>guest_username=virtual <br>listen=YES <br>listen_port=10021
<br>pasv_min_port=30000 <br>pasv_max_port=30999 <br>虚拟用户2 <br>===============
<br>这个例子将演示如何扩展&#8220;VIRTUAL_USERS&#8221;那个范例，从而实现更复杂一点的配置。<br>让我们假定我们需要2种不同的虚拟用户：一种只能浏览并下载资源，另一种能上传文件并浏览站内资源。<br>要激活这个设置，我们将使用VSFTPD的强大的&#8220;单个用户配置&#8221;功能（是V1.1.0后出现的新功能）。<br>在前一个虚拟用户范例中，我们创建了2个用户-tom和fred.
<br>我们将实现fred有写权限以上传新文件，同时tom只能下载文件。
<br><br>1）激活单个用户配置功能。<br>要激活这个功能，需要增加以下配置行到配置文件：
<br><br>user_config_dir=/etc/vsftpd_user_conf <br><br>并且创建目录： <br><br>mkdir
/etc/vsftpd_user_conf
<br><br>2）授予tom读取所有文件和目录的权限<br>在上一个例子的最后，我们注意到虚拟用户只能浏览所有的完全可读属性的目录和文件。我们使/home/ftpsite完全可读，而且被上传的文件也<br>赋予了完全可读的权限（daidong注：意思是说这样虚拟用户就能读取所有的文件了）。但实现这个目的的另一个方法是授权tom能下载那些非完全可读的文件。<br>对于tom,他的配置文件中需要修改一个设置：
<br>anon_world_readable_only: <br><br>设为"anon_world_readable_only=NO" &gt;
/etc/vsftpd_user_conf/tom
<br>(daidong注：既把默认配置修改了anon_world_readable_only后，复制到/etc/vsftpd_user_conf下，名字为tom)
<br><br>验证一下结果-以tom登录，&#8220;ls&#8221;将返回一个目录列表。如果以fred登录将不会如此。<br>注意：重启VSFTPD以启用配置文件/etc/vsftpd.conf(高级用户也可以发送SIGHUP给VSFTPD的监听进程).
<br><br>3)授予freg读取所有文件/目录并创建新文件/目录的权限,但让他不能对已存在的文件/目录进行操作. <br><br>echo
"anon_world_readable_only=NO" &gt; /etc/vsftpd_user_conf/fred <br>echo
"write_enable=YES" &gt;&gt; /etc/vsftpd_user_conf/fred <br>echo
"anon_upload_enable=YES" &gt;&gt; /etc/vsftpd_user_conf/fred
<br><br>验证一下-以tom登录,将不能上传,而fred就可以. <br>试图删除一个文件--噢,你们俩都不行!</font><br><img src ="http://www.cppblog.com/mydriverc/aggbug/109685.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2010-03-14 16:55 <a href="http://www.cppblog.com/mydriverc/archive/2010/03/14/109685.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>LINUX下FTP的搭建-wuftp</title><link>http://www.cppblog.com/mydriverc/archive/2010/03/14/109675.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Sun, 14 Mar 2010 06:27:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2010/03/14/109675.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/109675.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2010/03/14/109675.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/109675.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/109675.html</trackback:ping><description><![CDATA[<pre>FTP服务器的安装及管理-wuftp<br><br><strong>说明：</strong><br><em>    Linux下一般最常用的工具wu-ftpd.<br><br>    wu-ftpd的安装非常容易，大多数版本的Linux中都包含了wu-ftpd的rpm软件包，你可以在安装Linux时指定装入。如果你想自行编译源代码，也可以到ftp://ftp.wu-ftpd.org下载最新版本的源代码包。 <br><br>    安装好以后，可以用ckconfig命令来检查是否已经正确安装。在/etc/passwd中可以指定ftp用户的登入目录。 <br><br>    wu-ftpd主要有以下6个配置文件： <br><br>    ftpaccess(主要配置文件，控制存取权限) <br><br>    ftpconvertions(配置文件压缩/解压缩转换) <br><br>    ftpgroups(设定ftp自己定义的群组) <br><br>    ftphosts(设定个别的用户权限) <br><br>    ftpservers(设定不同IP/Domain Name以对应到不同的虚拟主机) <br><br>    ftpusers(设定哪些帐号不能用ftp连线)</em> <br>    <br>一. ftp服务器<br>1. inetd配置文件或xinetd.conf配置文件<br>   /etc/inetd.conf文件内容如下:<br>   ftp     stream  tcp     nowait  root    /usr/sbin/tcpd  in.ftpd -l -a <br><br>   /etc/xinetd.conf文件内容如下:<br>   service ftp<br>   {<br>           socket_type     = stream<br>           protocol        = tcp<br>           wait            = no<br>           user            = root<br>           #only_from       = 202.118.66.0<br>           #only_from       += 192.168.1.2<br>           #only_from       += localhost   <br>           server          = /usr/sbin/in.ftpd<br>           server_args     = -l -a<br>   }                                <br><br><br>   相关文件:/etc/services<br>   ftp-data        20/tcp<br>   ftp             21/tcp <br><br>2. ftp用户(Anonymous FTP服务器需要用到)<br>   文件:/etc/passwd和/etc/shadow<br>   <br>   /etc/passwd:<br>   ftp:x:500:50:Anonymous FTP User:/home/ftp:/bin/false <br><br>   /etc/shadow:<br>   ftp:*:10689:0:99999:7::: <br><br>   $finger ftp<br>   Login: ftp                              Name: FTP User<br>   Directory: /home/ftp                    Shell: /bin/false<br>   Never logged in.<br>   No mail.<br>   No Plan.              <br>   <br>3. DNS配置<br>   ftp  IN      CNAME   officail.domain.name.<br><br>4. 管理员邮件别名<br>   文件: /etc/mail/aliases (Solairs)<br>         /etc/aliases      (Linux)<br>         (egrep aliases /etc/mail/sendmail.cf )<br> <br>    ftp-admin:  real-user-name@domain.name<br><br>    相关命令: newaliases, 建立邮件别名<br><br><br>二. 文件系统结构<br> 1. Anonymous FTP 目录结构<br>    如下子目录:<br>    bin(ls,gzip,tar等anonymous ftp用户所要使用的二进制可执行文件)<br>    etc(passwd,group)<br>    lib(动态连接库,ld-2.0.7.so, ld-linux.so.2, ldd ../bin/ls 等)<br>    pub(可下载文件)<br><br> 2. passwd及group文件<br>    不要使用系统的passwd及group文件,最好只放所需的用户及组信息<br> passwd文件:<br>    ftpadm:x:0:0:Anonymous FTP:/home/ftp:/bin/false<br>    ftp:x:60000:60000:Anonymous FTP:/home/ftp:/bin/false <br> group文件:<br>    ftpadmin:x:0:<br>    ftp:x:60000:<br><br> 3. 文件及目录属性<br> 主目录/home/ftp   属主root, 属性555<br> bin    属主root 组wheel或other, 属性111<br> etc    同上<br> lib    属主root, 属性555<br> pub    属主为root或ftp管理员,属性555<br> <br> 确认不要用ftp作任何文件或目录的属主!<br><br> [hbwork@helius /etc]$ cd /home/ftp/<br> [hbwork@helius ftp]$ ls -l<br> total 4<br> d--x--x--x   2 root     root         1024 Apr  8 17:57 bin<br> d--x--x--x   2 root     root         1024 Jun  4 15:12 etc<br> drwxr-xr-x   2 root     root         1024 Apr  8 17:57 lib<br> dr-xr-sr-x   2 root     ftp          1024 Apr  8 11:18 pub <br> <br> $ls -l bin<br> [root@helius ftp]# ls -l bin/<br> total 250<br> ---x--x--x   1 root     root        15236 Apr 28  1998 compress<br> ---x--x--x   1 root     root        46356 Sep 11  1998 cpio<br> ---x--x--x   1 root     root        45436 Sep 11  1998 gzip<br> ---x--x--x   1 root     root        29980 Sep 11  1998 ls<br> ---x--x--x   1 root     root       110668 Sep 11  1998 tar<br> lrwxrwxrwx   1 root     root            4 May 19 16:48 zcat -&gt; gzip  <br><br> $ls -l etc<br> total 19<br> -r--r--r--   1 root     root           57 Jun  4 15:12 group<br> -r--r--r--   1 root     root        16372 Sep 11  1998 ld.so.cache<br> -r--r--r--   1 root     root           83 Jun  4 15:12 passwd <br><br>(在Solaris上建立anonymouse FTP特殊一些,请参考Wu-ftpd-faq)<br><br><br> 4. 可选目录<br>    incoming    Owner: root   Mode:1733 (chmod 1733 incoming)<br><br>三. 测试及调试<br>   egrep ftp /etc/inetd.conf<br>   ps ax |egrep inetd<br>   kill -HUP $PID<br><br>   $ftp localhost (or ftp 0)<br>   执行ls cd get 等指令看一下结果如何<br><br><br>四. wu-ftpd FTP服务器进程<br><br>   增强功能:<br>     . 允许根据用户的ip地址或主机,用户名设置不同的类<br>     . 根据设置的类,管理员可以控制其访问权限,如防止anonymous用户<br>       删除文件或覆盖已有的文件<br>     . 可以实现自动执行uncompress,compress,tar,gzip等功能<br>     . 可以记载所有的upload/download,及ftp client所发送的每个命令.<br>     . 允许平滑关掉ftp服务器<br><br>   相关配置文件:<br>       ftpaccess<br>       ftpconversions<br>       ftphosts<br>       ftpuser<br>       <br>       相关命令:<br>           strings /usr/sbin/in.ftpd |egrep ftpaccess<br><br>1. 编译 wu-ftpd<br><br>   最新版本: wu-ftpd-2.5.0<br>     ftp://ftp.dlut.edu.cn/pub/unix/ftp/servers/<br><br>   $tar -zxvf wu-ftpd-2.5.0.tar.gz<br>   $cd wu-ftpd-2.5.0<br>     建议在编译安装之前参考文件INSTALL,README,upload.configuration.HOWTO <br>     如想定制自己的wu-ftpd,可编辑文件src/pathnames.h<br>   $build help<br>      查看编译帮助<br>      <br>   $./build lnx<br>   $su<br>   #./build install<br><br>2. 命令行选项<br>   -d   Sends debugging information to syslog<br>   -a   Enable the use of the ftpaccess file(This is the default)<br>   -A   Disable the use of the ftpaccess file<br>   -L   Cause ftpd to log all USER commands.<br>   -i   Causes ftpd to log all incoming(upload) file in the xferlog <br>        file( See pathnames.h )<br>   -o   Causes ftpd to log all outgoing(download) files in the xferlog file<br><br>3. 文件ftpconversions<br>   doc/examples/, 用于指定get时的实时压缩或展开(on-the-fly).<br><br>   此文件不般情况下不用作修改<br><br>4. ftpaccess<br>  (1)定义类<br>      三种用户类型: real anonymous <br>                    guest(需要提供相应的口令)<br>      格式:<br>        class classname type[,type,...] address [ address ...]<br>  <br>      示例:<br>        class local real *.dlut.edu.cn 202.118.66 localhost<br>        class anonymous anonymous *<br><br><br>  (2)拒绝访问<br>     deny *.net.cn      /etc/ftpmsgs/msg.denied<br><br>  (3)限制访问<br>     limit class number times messages<br><br>     limit anonymous 200 SaSu<br>     limit anonymous 100 Any    /etc/ftpmsgs/msg.toomany<br><br>     <br>     loginfails 2 <br>     tar no anonymous<br>     compress no anonymous<br><br>     chmod      yes|no type [type ...]<br>     delete     yes|no type [type ...]<br>     overwrite  yes|no type [type ...]<br>     rename     yes|no type [type ...]<br>     umask      yes|no type [type ...]<br>     <br>     passwd-check       none|trivial|rfc822     enforce|warn<br><br>   (5)banner<br>      显示在用户login之前的信息<br>      banner    /etc/ftpmsg/banner.msg<br><br>      其中banner.msg文件中可以引用如下变量:<br>      %C        Current working directory<br>      %E        Email address of the administrator( email ftpadm@dlut.edu.cn)<br>      %F        可当目录下可用空间<br>      %L        hostname <br>      %M        最大允许连接数<br>      %N        同一类中当前连接数<br>      %R        The client host'name or ip address<br>      %T        Current local time<br>      %U        The name the user specified at login<br><br>      示例文件:<br>      Welcome to this test FTP Archive, running on %L.<br><br>      Please contact %E with any technical problems you may have<br>      accessing this archive.<br><br>      You are currently user %N out of a maximum %M users. It's<br>      %T in PRC.    <br><br>   (6)message命令<br>     message pathname login<br>     message pathname cwd=dir<br>     message .conents cwd=* <br>             每改变目录均显示,cwd=dir只在第一次更改时显示<br><br>   (7)readme命令<br>      readme pathname [login|cwd=dir] [class] [class]<br><br>      readme README* cwd=*<br><br>   (8)shutdown命令 (2.5.0上不正常)<br>      shutdown pathname<br><br>   (9)log命令<br><br>      log commands type [ type ...]<br><br>      log transfer type [type ...] direction[,direction]<br><br>   (10)alias <br>       alias source: /pub/local/sw/source<br><br>   (11)cdpath<br>       cdpath /pub /pub1<br><br>上载控制<br>   upload hierarchy directory yes|no owner group mode [dirs|nodirs]<br><br>下面的wu-ftpd-2.5.0 /etc/ftpaccess文件中的upload配置(大家可以试一下大工FTP<br>服务器的upload,但别传没用的过大的文件)<br><br># FTP-home-dir          archiv-dir      allow?  owner   group   mode    dirs?<br># (as in /etc/passwd)<br><br>upload  /home/ftp       *               no<br>upload  /home/ftp       /pub3/incoming/windows yes ftpadmin ftp  0664  dirs<br>upload  /home/ftp       /pub3/incoming/windows/* yes ftpadmin ftp 0664 dirs<br>upload  /home/ftp       /pub3/incoming/unix     yes     ftpadmin ftp   0666 dirs<br>upload  /home/ftp       /pub3/incoming/unix/*   yes     ftpadmin ftp   0666 dirs<br>upload  /home/ftp       /pub3/incoming/other    yes     ftpadmin ftp   0666 dirs<br>upload  /home/ftp       /pub3/incoming/other/*  yes     ftpadmin ftp   0666 dirs<br>upload  /home/ftp       /pub3/incoming/WDI      yes     ftpadmin ftp   0666 dirs<br>upload  /home/ftp       /pub3/incoming/WDI/*    yes     ftpadmin ftp   0666 dirs<br><br><br>5. ftphosts文件<br>   allow ftp    *.dlut.edu.cn<br>   allow anonymous *.dlut.edu.cn<br>   deny ftp *.dlmu.edu.cn<br>   deny ftp *.dlmu.edu.cn 202.118.80.*<br><br><br>6.实用程序<br><br>  ftpcount<br>  ftpwho<br>  ftushut<br><br>维护:<br>    建立连接时最好使用相对路径。<br>    根据软件类别建立不同的子目录。<br>    最好在每个目录中建立相应的说明文件或index文件，方便用户查找。</pre><img src ="http://www.cppblog.com/mydriverc/aggbug/109675.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2010-03-14 14:27 <a href="http://www.cppblog.com/mydriverc/archive/2010/03/14/109675.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iptables 下开放ftp</title><link>http://www.cppblog.com/mydriverc/archive/2010/03/14/109674.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Sun, 14 Mar 2010 06:24:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2010/03/14/109674.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/109674.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2010/03/14/109674.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/109674.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/109674.html</trackback:ping><description><![CDATA[这两天在给客户安装服务器时也顺便给他们使用iptables，不用不知道，一用才发现iptables还有很多东西可以学的，比如开放ftp。<br>iptables
的filter表的INPUT链的默认策略设为了DROP，其余的链均为ACCEPT。
该服务器即要作ftp服务器，也要连上别的ftp服务器。即是说要把源端口和目的端口都开放21才行：<br>iptables -A INPUT -p tcp
&#8211;sport 21 -j ACCEPT<br>iptables -A INPUT -p tcp &#8211;dport 21 -j
ACCEPT<br>开了21端口就行了吗？不是的。先说说ftp协议。ftp协议是一个简单、保密性差（明码）的tcp协议，它的工作原理是客户端先连服务器端
的21端口，然后经过3步的握手以后建立了一条连接。要注意的是，这条连接只可以用来传输ftp的命令，只有这条连接的话是什么都传不了的，就算是用
&#8220;ls&#8221;命令来查看文件也不行。<br>建立了命令的连接以后，服务器端就要建立一条数据的连接。数据的连接又分为主动模式（port）和被动模式（passive）。ftp默认是被动
模式，主动和被动之间使用&#8221;pass&#8221;命令切换。主动模式通过20端口与客户端相连，而被动模式却使用1024以后的端口与客户端相连。由于1024以后
的端口是随机分配的，所以在被动模式下我们是不知道服务端是使用什么端口与客户端连接的。也就是说，我们是不知道iptables要开放什么端口。<br>开始我使用的是<br>iptables
-A input -p tcp &#8211;sport 1024: &#8211;dport 1024: -j
ACCEPT<br>来让ftp建立被动连接的。但觉得如果这样的话，那就等于把所以p2p的连接都开放了，不安全。<br>于是在CU上问人，终于找到了解决的方法:<br>1、加载模块。<br><font color="#ff2424"><br>modprobe ip_nat_ftp<br>modprobe ip_conntrack<br>modprobe
ip_conntrack_ftp<br></font><br>2,加上一条规则：<br><font color="#ff2424">处于server<br>iptables -A INPUT -m state &#8211;state ESTABLISHED,RELATED
-j ACCEPT</font><br><font color="#ff2424">处于client</font><br><font color="#ff2424">iptables -A OUTPUT -m state &#8211;state ESTABLISHED,RELATED -j
ACCEPT<br></font><br>允许连接保持的被动访问。<br>其实这样在重启iptables的时候所需的模块又不见了，通过不懈的努力终于找到了最终的解决方法，编辑/etc/sysconfig/iptables-config：<br>IPTABLES_MODULES="ip_conntrack_ftp"<br>IPTABLES_MODULES="ip_nat_ftp"<br>把需要加载的模块加入，无论重启系统还是iptables但ftp模块始终还是加载的。<br>搞定就这样哈哈哈，希望能在以后帮助大家来解决ftp上的问题。<br><br><br><strong>本文来自ChinaUnix博客，如果查看原文请点：</strong><a  href="http://blog.chinaunix.net/u1/51714/showart_423414.html" target="_blank">http://blog.chinaunix.net/u1/51714/showart_423414.html</a> <img src ="http://www.cppblog.com/mydriverc/aggbug/109674.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2010-03-14 14:24 <a href="http://www.cppblog.com/mydriverc/archive/2010/03/14/109674.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux iptables配置FTP的主动和被动模式</title><link>http://www.cppblog.com/mydriverc/archive/2010/03/14/109670.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Sun, 14 Mar 2010 06:18:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2010/03/14/109670.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/109670.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2010/03/14/109670.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/109670.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/109670.html</trackback:ping><description><![CDATA[<div class="cnt" id="blog_text">
<p>先理解主被动的联接方式：</p>
<p>FTP协议有两种工作方式：PORT方式和PASV方式，中文意思为主动式和被动式。</p>
<p><font color="#ff0000">Port<a  href="http://www.net527.cn/a/luyoujiaohuan/"><u>模式</u></a>：</font>ftp server:tcp
21 &lt;------client:dynamic&nbsp;&nbsp;&nbsp; ftp server:tcp 20 ------&gt;client:dynamic</p>
<p><font color="#ff0000">Pasv模式：</font>ftp server:tcp 21
&lt;----client:dynamic&nbsp;&nbsp;&nbsp;&nbsp; ftp server:tcp dynamic
&lt;----client:dynamic<br><font color="#ff0000">PORT（主动）</font>方式的<a  href="http://www.net527.cn/a/luyoujiaohuan/"><u>连接</u></a>过程是：客户端向服务器的FTP端口（默认是21）发送<a  href="http://www.net527.cn/a/luyoujiaohuan/"><u>连接</u></a>请
求，服务器接受连接，建立一条命令链路。当需要传送数据时，客户
端在命令链路上用PORT命令告诉服务器：&#8220;我打开了XXXX端口，你过来连接我&#8221;。于是服务器从20端口向客户端的XXXX端口发送连接请求，建立一条
数据链路来传送数据。<br><font color="#ff0000">PASV（被动）</font>方式的连接过程是：客户端向服务器的FTP端口（默认是21）发送连接请
求，服务器接受连接，建立一条命令链路。当需要传送数据时，服务
器在命令链路上用PASV命令告诉客户端：&#8220;我打开了XXXX端口，你过来连接我&#8221;。于是客户端向服务器的XXXX端口发送连接请求，建立一条数据链路来
传送数据。</p>
<p><font face="宋体"><br></font></p>
<p><font face="宋体">#allow all ftp incoming connections<br>iptables -A INPUT -p tcp
--dport 21 -m state --state ESTABLISHED -j ACCEPT<br>iptables -A OUTPUT -p tcp
--sport 21 -m state --state NEW,ESTABLISHED -j ACCEPT</font></p>
<p><font face="宋体"># Enable active ftp transfers<br>iptables -A INPUT -p tcp
--dport 20 -m state --state ESTABLISHED,RELATED -j ACCEPT<br>iptables -A OUTPUT
-p tcp --sport 20 -m state --state ESTABLISHED -j ACCEPT</font></p>
<p><font face="宋体"># Enable passive ftp transfers<br>iptables -A INPUT -p tcp
--sport 1024:65535 --dport 1024:65535 -m state --state ESTABLISHED -j
ACCEPT<br>iptables -A OUTPUT -p tcp --sport 1024:65535 --dport 1024:65535 -m
state --state ESTABLISHED,RELATED -j ACCEPT</font></p>
</div><img src ="http://www.cppblog.com/mydriverc/aggbug/109670.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2010-03-14 14:18 <a href="http://www.cppblog.com/mydriverc/archive/2010/03/14/109670.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>查看某组的所有用户</title><link>http://www.cppblog.com/mydriverc/archive/2009/11/11/100744.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Wed, 11 Nov 2009 14:30:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/11/11/100744.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/100744.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/11/11/100744.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/100744.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/100744.html</trackback:ping><description><![CDATA[gawk 'BEGIN {FS=":"} $4=="504" {print $1}' /etc/passwd<br><br>504是组的ID<br><br><img src ="http://www.cppblog.com/mydriverc/aggbug/100744.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-11-11 22:30 <a href="http://www.cppblog.com/mydriverc/archive/2009/11/11/100744.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[Linux命令]格式化mkfs</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/22/99244.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Thu, 22 Oct 2009 15:19:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/22/99244.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/99244.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/22/99244.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/99244.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/99244.html</trackback:ping><description><![CDATA[指令：mkfs
<br>
<br>使用权限 : 超级使用者
<br>
<br>使用方式 : mkfs [-V] [-t fstype] [fs-options] filesys [blocks]
<br>
<br>说明 ： 建立 linux 档案系统在特定的 partition 上
<br>
<br>
<br>参数 ：
<br>
<br>device ： 预备检查的硬盘 partition，例如：/dev/sda1
<br>-V : 详细显示模式
<br>-t : 给定档案系统的型式，Linux 的预设值为 ext2
<br>-c : 在制做档案系统前，检查该partition 是否有坏轨
<br>-l bad_blocks_file : 将有坏轨的block资料加到 bad_blocks_file 里面
<br>block : 给定 block 的大小
<br>
<br>例：
<br>1.在 /dev/hda5 上建一个 msdos 的档案系统，同时检查是否有坏轨存在，并且将过程详细列出来 :
<br>mkfs -V -t msdos -c /dev/hda5
<br>2.
<br>mkfs.ext3&nbsp;/dev/sda1
<br>3.
<br>mkfs.ext3&nbsp;/dev/sda2<img src ="http://www.cppblog.com/mydriverc/aggbug/99244.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-22 23:19 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/22/99244.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>深入Linux的LILO</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/15/98735.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Thu, 15 Oct 2009 15:34:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/15/98735.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98735.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/15/98735.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98735.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98735.html</trackback:ping><description><![CDATA[Linux的引导可以采用多种方式，其加载器LILO(Linux Loader) <br>
是一个灵活的引导加载程序，与其他常用的引导加载程序相比，LILO 引导方式显得更具有艺术性，对其深入的理解，将有助于我们方便地 处理多重系统、网络引导、大硬盘及大内存等诸多棘手的问题。 <br>
<br>
一、LILO的引导机制 <br>
<br>
众所周知，计算机的最初启动是由BIOS控制的，在对一些硬件 （如：内存、键盘等）初始化之后，它会试图加载硬盘的主引导记录 （MBR）或软盘的引导扇区。 <br>
<br>
MBR可通过两种方式运行，其一是定位到活动分区并加载相应的 引导扇区，然后由引导扇区完成该分区内操作系统的基本组件的加载
；其二是直接从一指定分区中加载信息，并通过它装入任一分区的操 作系统，诸如LILO、OS/2 boot loader及Partition
Magic等引导加载 程序都可以配置成这种方式。 <br>
<br>
软盘的引导扇区相当于硬盘活动分区的引导扇区，它通常用于装 入软盘上的操作系统。 <br>
<br>
由此可见，只要把LILO安装在MBR、活动分区或者引导软盘上， 就能接管计算机的控制权，然后由LILO完成后继的引导过程。LILO中
建有一个引导表地址编码，借此它的引导程序就能定位到Linux的内 核文件，这种地址编码既可以按照柱面/磁头/扇区(CHS)模式，又可
以采用LBA的线性块号模式，因此，即使对某些SCSI控制程序LILO也 能运转良好。 <br>
<br>
当LILO定位到配置文件后，经过预引导过程，就显示提示符： LILO boot: <br>
<br>
此时，系统答应选择引导不同的操作系统或者不同的内核配置， 按Tab键显示可选项列表，然后输入可选项或者直接回车选择缺省配 置，假如选择了引导Linux，还可以直接传递参数到系统内核。 <br>
<br>
和其他系统的引导加载程序相比，LILO具有更大的灵活性，其引 导方式也更丰富多彩。 <br>
<br>
●当LILO被安装在硬盘的MBR、活动分区或引导软盘上时，作为 原引导程序的替身，它能引导任一硬盘任一分区上的Linux和其他操 作系统； <br>
<br>
●除了引导扇区，它没有任何隐含文件，也不需要使用特定的分 区，它的配置文件可以在任何分区、甚至是存放在与Linux毫不相干 的DOS分区的某个子目录下； <br>
<br>
●它能引导几个不同的内核配置，甚至是几个不同的内核； <br>
<br>
●它能引导同一机程序上的多个Linux版本； <br>
<br>
●它能从网络上引导Linux。 <br>
<br>
LILO的灵活性使得其配置变得相当复杂，当有多个系统共存时， 建议先安装其他操作系统，最后再装Linux，这样，设置LILO对其他 系统的引导会相对简单一些。 <br>
<br>
二、几个重要的LILO引导参数 <br>
<br>
LILO的引导参数有很多，在此只对一些比较重要的参数作一介绍 。 <br>
1.&#8220;boot=&#8221; <br>
<br>
此参数指明包含引导扇区的设备名（如：/dev/had），若此项忽 略，则从当前的根分区中读取引导扇区。 <br>
<br>
2.&#8220;root=&#8221; <br>
<br>
此参数告诉内核启动时以哪个设备作为根文件系统使用，其设定 值为构造内核时根文件系统的设备名，可用的设备名有： <br>
<br>
(1)/dev/hdaN~/dev/hddN：ST-506兼容硬盘，a到d上的N个分区 <br>
(2)/dev/sdaN~/dev/sdeN：SCSI兼容硬盘，a到e上的N个分区 <br>
(3)/dev/xdaN~/dev/xdbN：XT兼容硬盘，a到b上的N个分区 <br>
(4)/dev/fdN：软盘，A：（N=0）或B：（N=1） <br>
(5)/dev/nfs：由网络取得根文件系统的标志 <br>
<br>
3.&#8220;nfsroot=&#8221; <br>
若需通过NFS提供根文件系统来引导无盘工作站，此参数为内核 指定了网络根文件系统所在的机程序、目录及NFS，其格式为：nfsroot= （〈server_ip〉:）〈root_dir〉（,nfs_options〉） <br>
<br>
4.&#8220;nfsaddrs=&#8221; <br>
设定网络通讯所需的各种网络界面地址，如无此参数，则内核会 试图用反向地址解析协定(RARP)或启动协定(BOOTP)找出这些参数， <br>
其格式为： <br>
<br>
nfsaddrs=〈客户端IP〉:〈服务端IP〉:〈网关IP〉:〈子网屏蔽〉: 〈客户端名称〉:〈<a  href="http://network.chinaitlab.com/" class="channel_keylink" target="_blank">网络设备</a>名　〉:〈auto〉 <br>
<br>
5.&#8220;image=&#8221; <br>
指定Linux的内核文件。 <br>
<br>
6.&#8220;delay=&#8221; <br>
设定引导第一个映像前的等待时间。 <br>
<br>
7.&#8220;disk=&#8221; <br>
此参数为某一非凡的硬盘定义非标准参数。 <br>
<br>
8.&#8220;append=&#8221; <br>
为内核传递一个可选的参数行，其典型的应用是为不能完全由系 统自动识别的硬盘指定参数，如：append = "hd=64,32,202" <br>
<br>
9.&#8220;label=&#8221; <br>
此参数为每个映像指定一个名字，以供引导时选择。 <br>
<br>
10.&#8220;read-only&#8221; <br>
设定以只读方式挂入根文件系统，用于文件系统一致性检查（fsck） <br>
。 <br>
<br>
11.&#8220;install=&#8221; <br>
安装一个指定文件作为新的引导扇区，缺省为/boot/boot.b。 <br>
<br>
12.&#8220;loader=&#8221; <br>
说明所使用的链加载程序(chain loader)，缺省为/boot/chain.b， 　假如不是从首硬盘或软盘启动，那么，此选项必须说明。 <br>
<br>
13.&#8220;table=&#8221; <br>
说明包含分区表的设备名，假如此参数忽略，引导加载程序将不 能传递分区信息到已引导的操作系统。当此参数指向的分区表被修改 时，必须重新运行/sbin/lilo。 <br>
<br>
14.&#8220;init=&#8221; <br>
内核初始化时执行的程序，通常过程为init、getty、rc和sh， 　版本1.3.43以来的Linux内核能够执行/sbin/init说明的命令行，若 在引导过程中出现问题，则可设置init=/bin/sh直接跳到Shell。 <br>
<br>
15.&#8220;ramdisk_start=&#8221; <br>
由于内核不能放在压缩的内存文件系统映像内，为使内核映像能 够和压缩的内存映像放在一张软盘内，加入&#8220;ramdisk_start=〈offset〉&#8221;，这样内核才? 开始执行。 <br>
<br>
16.&#8220;mem=&#8221; <br>
此参数的目的之一是为Linux指定使用的内存数量：如mem=96MB， 目的之二是指定mem=nopentium告诉内核不要使用４MB分页表。 <br>
<br>
17.&#8220;vga=&#8221; <br>
设置显示模式，如80&#215;50、132&#215;44等。 <br>
<br>
三、LILO典型配置方法 <br>
<br>
通常情况下，Linux的安装程序自身就可以完成LILO的安装配置， 从而较好地解决多重系统的引导问题，假如系统不能自动完成这种配 置，则可以通过手工修改配置文件/etc/lilo.conf来实现不同条件下 的引导。 <br>
<br>
1.当系统能自动完成配置时 <br>
<br>
对于这种情况只有一个建议：将LILO安装到Linux分区的根上， 而不是MBR这个多事地带。假设当前hda1中装有DOS/<a  href="http://windows.chinaitlab.com/" class="channel_keylink" target="_blank">Windows</a>，hda2中 安装了Linux，则/etc/lilo.conf的内容大致如下： <br>
<br>
boot=/dev/hda2＃指定引导位置compact delay=50＃延时５秒root=current <br>
＃根在当前分区image=/boot/vmlinuz＃指定<a  href="http://linux.chinaitlab.com/" class="channel_keylink" target="_blank">linux</a>的内核文件　　label=<a  href="http://linux.chinaitlab.com/" class="channel_keylink" target="_blank">linux</a> <br>
＃用linux为代表名称　other=/dev/hda1＃其他操作系统所在的分区table=/dev/had <br>
＃指定包含分区表的硬盘label=dos＃用dos为代表名称 <br>
<br>
2.当系统无法自动完成配置时 <br>
<br>
系统无法自动完成配置的情况不外乎两种： <br>
（1）BIOS不能直接看到Linux的根分区； <br>
（2）BIOS只能读写标准IDE硬盘的前504MB。 <br>
<br>
这时，必须遵循一个最基本的原则：建立一个BIOS能存取的较小 的Linux分区，其中包含内核文件、映射文件及链加载程序等必要内 容，而根则可以是另外一个独立的分区。至于配置上的其他细节，我 们通过以下实例来进行说明。 <br>
<br>
<br>
例１：主硬盘为IDE接口，第二硬盘为SCSI接口，根文件在SCSI 上。 <br>
<br>
对策：在IDE硬盘上划分一个较小的Linux分区（/dev/hda2）， 　其中包含基本文件，挂接到/u2下，其配置文件/etc/lilo.conf的主 要内容为： <br>
<br>
boot=/dev/had＃lilo装在主ide的mbr <br>
install=/u2/etc/lilo/boot.b＃从boot.b安装lilo引导记录 <br>
map=/u2/etc/lilo/map＃安装程序建立此映射文件，告诉引导载入程序内核块的位置 <br>
compact <br>
timeout=50 <br>
image=/u2/vmlinuz ＃内核文件应事先拷贝到/u2下 <br>
label=linux <br>
root=/dev/sda1＃告诉内核根系统在scsi硬盘上read-only <br>
other=/dev/hda1 <br>
loader=/u2/etc/lilo/chain.b ＃指明加载程序label=dos <br>
<br>
例２：一个标准的IDE大硬盘需安装Linux和DOS/<a  href="http://windows.chinaitlab.com/" class="channel_keylink" target="_blank">Windows</a>。 <br>
对于大硬盘问题，很多人只知道低于1024个柱面的限制，而不知 为什么标准的IDE硬盘只能认前504MB。 <br>
<br>
其实，BIOS的int13调用是采用三个位元组的CHS编码，10位为柱 面号，8位为磁头号，6位为扇区号。可能的柱面号码是0～1023，可
能的磁头号码是0～255，而磁道上可能的扇区号码是1～63，以这24 位最多可以定址8455716864个位元组(7.87<img src ="http://www.cppblog.com/mydriverc/aggbug/98735.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-15 23:34 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/15/98735.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> Linux LVM </title><link>http://www.cppblog.com/mydriverc/archive/2009/10/14/98631.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Wed, 14 Oct 2009 15:24:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/14/98631.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98631.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/14/98631.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98631.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98631.html</trackback:ping><description><![CDATA[<h1 class="title_txt">
<img  src="http://hi.images.csdn.net/images/blog/authorship.gif" alt="原创" border="0" height="16" width="15">&nbsp;
Linux LVM
<cite class="fav_csdnstylebykimi">
<a  href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(saveit=window.open('http://wz.csdn.net/storeit.aspx?t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t),'saveit','scrollbars=no,width=590,height=300,left=75,top=20,status=no,resizable=yes'));saveit.focus();" class="fav_csdnstylebykimi" title="收藏到我的网摘中，并分享给我的朋友">收藏</a>
</cite>
</h1>
<script type="text/javascript">
document.body.oncopy = function() {
if (window.clipboardData) {
setTimeout(function() {
var text = clipboardData.getData("text");
if (text && text.length>300) {
text = text + "\r\n\n本文来自CSDN博客，转载请标明出处：" + location.href;
clipboardData.setData("text", text);
}
}, 100);
}
}
</script>
<script type="text/javascript">function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script>
<p>对
于Linux用户而言，在安装一台Linux机器的时候，遇到的问题之一就是给各分区估计和分派足够的硬盘空间。无论对一个正在为服务器寻找空间的系统管
理员，还是一个磁盘即将用尽的普通用户来说，这都是一个非常常见的问题。解决的方法通常是使用符号链接，或者一些调整分区大小的工具(比如
parted)。但是，这只是一个暂时性的解决办法，不久，我们又会面临同样的问题。 </p>
<p>　　如果你是一个站点的系统管理员，管理着数量众多的、连接在Internet之上的服务器，那么你每关机一分钟，都会给公司带来很大损失。此外，使用这种方法，在修改了分区表之后，每一次都得重新启动系统。LVM(逻辑卷管理程序)可以帮助我们解决这些问题。 </p>
<p>LVM简介</p>
<p>　　Linux LVM可以使管理工作更加轻松。相对于硬盘和分区，LVM是从更高的层次来看待存储空间的。在使用LVM之前，先来看一些将要使用到的相关概念。 </p>
<p>物理卷 </p>
<p>　　物理卷是指硬盘分区或者从逻辑上看起来和硬盘分区类似的设备(比如RAID设备)。 </p>
<p>逻辑卷 </p>
<p>　　一个或者多个物理卷组成一个逻辑卷。对于LVM而言，逻辑卷类似于非LVM系统中的硬盘分区。逻辑卷可以包含一个文件系统(比如/home或者/usr)。 </p>
<p>卷组 </p>
<p>　　一个或者多个逻辑卷组成一个卷组。对于LVM而言，卷组类似于非LVM系统中的物理硬盘。卷组把多个逻辑卷组合在一起，形成一个可管理的单元。 </p>
<p><br>LVM工作方式</p>
<p style="font-weight: bold;">　　下面来看一看LVM到底是怎样工作的。每一个物理卷都被分成几个基本单元，即所谓的PE(Physical
Extents)。PE的大小是可变的，但是必须和其所属卷组的物理卷相同。在每一个物理卷里，每一个PE都有一个惟一的编号。PE是一个物理存储里可以
被LVM寻址的最小单元。 </p>
<p style="font-weight: bold;">　　每一个逻辑卷也被分成一些可被寻址的基本单位，即所谓的LE(Logical Extents)。在同一个卷组中，LE的大小和PE是相同的，很显然，LE的大小对于一个卷组中的所有逻辑卷来说都是相同的。 </p>
<p>　　在一个物理卷中，每一个PE都有一个惟一的编号，但是对于逻辑卷这并不一定是必需的。这是因为当这些PE
ID号不能使用时，逻辑卷可以由一些物理卷组成。因此，LE
ID号是用于识别LE以及与之相关的特定PE的。正如前面所提到的，LE和PE之间是一一对应的。每一次存储区域被寻址访问或者LE的ID被使用，都会把
数据写在物理存储设备之上。 </p>
<p>　　你可能会觉得奇怪，有关逻辑卷和逻辑卷组的所有元数据都存到哪儿去了。类似的在非LVM系统中，有关分区的数据是存储在分区表中，而分区表被存储在了每一个物理卷的起始位置。VGDA(卷组描述符区域)功能就好象是LVM的分区表，它存储在每一个物理卷的起始处。 </p>
<p>　　VGDA由以下信息组成： </p>
<p>　　◆ 一个PV描述符 <br>　　◆ 一个VG描述符 <br>　　◆ LV描述符 <br>　　◆ 一些PE描述符</p>
<p>　　当系统启动LV时，VG被激活，并且VGDA被加载至内存。VGDA帮助识别LV的实际存储位置。当系统想要访问存储设备时，由VGDA建立起来的映射机制就用于访问实际的物理位置来执行I/O操作。 </p>
<p>开始工作</p>
<p>　　下面具体看一看如何使用LVM。 </p>
<p>　　第一步：配置内核。在安装LVM之前，内核之中应该有LVM模块，可以使用以下的步骤来完成： </p>
<p><br>　　#cd /usr/src/linux<br>　　#make menuconfig</p>
<p>&nbsp;</p>
<p>　　选择Multi-device Support (RAID and LVM)子菜单，选中以下两个选项： </p>
<p><br>　　[*] Multiple devices driver support (RAID and LVM)<br>　　&lt;*&gt; Logical volume manager (LVM) Support.</p>
<p>&nbsp;</p>
<p>　　第二步：检查驱动器上空闲硬盘空间的总量。这可以通过以下命令来未完成： </p>
<p><br>　　# df -h<br>　　Filesystem Size Used Avail Use% Mounted on<br>　　/dev/hda1 3.1G 2.7G 398M 87% /<br>　　/dev/hda2 4.0G 3.2G 806M 80% /home<br>　　/dev/hda5 2.1G 1.0G 1.1G 48% /var</p>
<p>&nbsp;</p>
<p>　　第三步：在硬盘上创建一个LVM分区。使用fdisk或者其它的分区工具来创建一个LVM分区。Linux LVM的分区类型为8e。 </p>
<p><br>　　# fdisk /dev/hda<br>　　press p (to print the partition table) and n (to create a new partition)</p>
<p>&nbsp;</p>
<p>　　第四步：创建一个物理卷。下述命令将在分区的起始处创建一个卷组描述符： </p>
<p><br>　　# <strong><font color="#ff1493">pvcreate /dev/hda6</font></strong><br>　　pvcreate -- -physical volume "/dev/hda6" successfully created<br>　　# pvcreate /dev/hda7<br>　　pvcreate- -- physical volume "/dev/hda7" successfully created</p>
<p>&nbsp;</p>
<p>　　第五步：创建一个卷组。通过下面的方法创建一个新的卷组，并且添加两个物理卷： </p>
<p><br>　　# <font color="#ff1493"><strong>vgcreate test_lvm /dev/hda6 /dev/hda7<br></strong></font>　　vgcreate- -- INFO: using default physical extent size 4 MB<br>　　vgcreate- -- INFO: maximum logical volume size is 255.99 Gigabyte<br>　　vgcreate- -- doing automatic backup of volume group "test_lvm"<br>　　vgcreate- -- volume group "test_lvm" successfully created and activated</p>
<p>&nbsp;</p>
<p>　　上述命令将创建一个名为test_lvm，包含有/dev/hda6和/dev/hda7两个物理卷的卷组。使用下面命令来激活卷组： </p>
<p><br>　　# <strong><font color="#ff1493">vgchange -ay test_lvm</font></strong></p>
<p>&nbsp;</p>
<p>　　使用&#8220;vgdisplay&#8221;命令来查看所建立卷组的细节信息。 </p>
<p><br>　　# <font color="#ff1493"><strong>vgdisplay<br></strong></font>　　--- Volume group ---<br>　　VG Name test_lvm<br>　　VG Access read/write<br>　　VG Status available/resizable<br>　　VG # 0<br>　　MAX LV 256<br>　　Cur LV 1<br>　　Open LV 0<br>　　MAX LV Size 255.99 GB<br>　　Max PV 256<br>　　Cur PV 2<br>　　Act PV 2<br>　　VG Size 3.91 GB<br>　　PE Size 4 MB<br>　　Total PE 1000<br>　　Alloc PE / Size 256 / 1 GB<br>　　Free PE / Size 744 / 2.91 GB<br>　　VG UUID T34zIt-HDPs-uo6r-cBDT-UjEq-EEPB-GF435E</p>
<p>&nbsp;</p>
<p>　　第六步：创建一个逻辑卷。使用lvcreate命令在卷组中创建一个逻辑卷： </p>
<p><br>　　#<font color="#ff1493"><strong> lvcreate -L2G -nlogvol1 test_lvm</strong></font></p>
<p>&nbsp;</p>
<p>　　第七步：创建文件系统。在该逻辑卷上选择使用reiserfs日志文件系统： </p>
<p><br>　　# <strong><font color="#ff1493">mkreiserfs /dev/test_lvm/logvol1</font></strong></p>
<p>&nbsp;</p>
<p>　　使用mount命令来加载新创建的文件系统。 </p>
<p><br>　　# <font color="#ff1493"><strong>mount -t reiserfs /dev/test_lvm/logvol1 /mnt/lv1</strong></font></p>
<p>&nbsp;</p>
<p>　　第八步：在/etc/fstab和/etc/lilo.conf中添加一个入口。在/etc/fstab中加入以下入口，在启动时加载文件系统： </p>
<p><br>　　<strong><font color="#ff1493">/dev/test_lvm/logvol1 /mnt/lv1 reiserfs defaults 1 1</font></strong></p>
<p>&nbsp;</p>
<p>　　如果没有覆盖原来的内核，那么拷贝一份重新编译后的内核，并且在启动时选择是否使用LVM。下面是LILO文件的内容： </p>
<p><br>　　image = /boot/lvm_kernel_image<br>　　label = linux-lvm<br>　　root = /dev/hda1<br>　　initrd = /boot/init_image<br>　　ramdisk = 8192</p>
<p>&nbsp;</p>
<p>　　添加以上内容后，使用以下命令重新加载LILO： </p>
<p><br>　　#/sbin/lilo</p>
<p>&nbsp;</p>
<p>　　第九步：修改逻辑卷的大小。可以使用lvextend命令方便地修改逻辑卷的大小，增加逻辑卷大小的方法如下： </p>
<p><br>　　# <strong><font color="#ff1493">lvextend -L+1G /dev/test_lvm/logvol1</font></strong><br>　　lvextend -- extending logical volume "/dev/test_lvm/logvol1" to 3GB<br>　　lvextend -- doing automatic backup of volume group "test_lvm"<br>　　lvextend -- logical volume "/dev/test_lvm/logvol1" successfully extended</p>
<p><br>　　 <br>　　类似的，减小逻辑卷大小的方法如下： </p>
<p><br>　　# <strong><font color="#ff1493">lvreduce -L-1G /dev/test_lvm/lv1<br></font></strong>　　lvreduce -- -Warning: reducing active logical volume to 2GB<br>　　lvreduce- -- This may destroy your data (filesystem etc.)<br>　　lvreduce -- -do you really want to reduce "/dev/test_lvm/lv1"? [y/n]: y<br>　　lvreduce- -- doing automatic backup of volume group "test_lvm"<br>　　lvreduce- -- logical volume "/dev/test_lvm/lv1" successfully reduced</p><img src ="http://www.cppblog.com/mydriverc/aggbug/98631.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-14 23:24 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/14/98631.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux中的dmesg了解</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/13/98534.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Tue, 13 Oct 2009 15:16:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/13/98534.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98534.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/13/98534.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98534.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98534.html</trackback:ping><description><![CDATA[　　dmesg 是一个显示内核缓冲区系统控制信息的工具;比如系统在启动时的信息会写到/var/log/<br>
<br>
注:dmesg 工具并不是专门用来查看硬件芯片组标识的工具，但通过这个工具能让我们知道机器中的硬件的一些参数;因为系统在启动的时候，会写一些硬件相关的日志到 /var/log/message* 或<br>
/var/log/boot* 文件中;<br>
<br>
如果我们用这个工具来查看一些硬件的信息;这个工具信息量太大，的确需要耐心;<br>
<br>
[root@panda ~]# dmesg<br>
[root@panda ~]# dmesg -c 注:清理掉缓冲区，下次开机的时候还会自动生成;<br><br><br><br><strong>功能说明：</strong>显示开机信息。<br><br><strong>语　　法：</strong>dmesg&nbsp;[-cn][-s&nbsp;&lt;缓冲区大小&gt;]<br><br><strong>补充说明：</strong>kernel会将开机信息<a  href="http://www.storworld.com/" class="channel_keylink" target="_blank">存储</a>在ring&nbsp;buffer中。您若是开机时来不及查看信息，可利用dmesg来查看。开机信息亦保存在/var/log目录中，名称为dmesg的文件里。<br><br><strong>参　　数：</strong><br>　-c&nbsp;　显示信息后，清除ring&nbsp;buffer中的内容。&nbsp;<br>　-s&lt;缓冲区大小&gt;&nbsp;　预设置为8196，刚好等于ring&nbsp;buffer的大小。&nbsp;<br>　-n&nbsp;　设置记录信息的层级。 <br><img src ="http://www.cppblog.com/mydriverc/aggbug/98534.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-13 23:16 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/13/98534.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>查看硬件</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/13/98533.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Tue, 13 Oct 2009 15:14:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/13/98533.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98533.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/13/98533.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98533.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98533.html</trackback:ping><description><![CDATA[lspci<br>
lsusb<br>fdisk -l<br>
df<br>
dmesg<br>UNE2FS;PARTED<br><img src ="http://www.cppblog.com/mydriverc/aggbug/98533.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-13 23:14 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/13/98533.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux查看硬件信息及驱动设备</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/13/98532.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Tue, 13 Oct 2009 15:10:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/13/98532.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98532.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/13/98532.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98532.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98532.html</trackback:ping><description><![CDATA[<div class="g_blog_list">
<div class="g_t_center g_c_pdin g_p_center c07 content" id="blogtext_fks_082065086082089065083084085095085084080074081086083">
<div class="ns_content">
<p style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: 9pt; font-family: 宋体;">用硬件检测</span><span style="font-size: 9pt; font-family: 宋体;">程序</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">kudzu</span><span style="font-size: 9pt; font-family: 宋体;">探测新硬件：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">service kudzu start ( or restart)<br></span><span style="font-size: 9pt; font-family: 宋体;">查看</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">CPU</span><span style="font-size: 9pt; font-family: 宋体;">信息：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">cat /proc/cpuinfo<br></span><span style="font-size: 9pt; font-family: 宋体;">查看板卡信息：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">cat /proc/pci<br></span><span style="font-size: 9pt; font-family: 宋体;">查看</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">PCI</span><span style="font-size: 9pt; font-family: 宋体;">信息：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">lspci (</span><span style="font-size: 9pt; font-family: 宋体;">相比</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">cat /proc/pci</span><span style="font-size: 9pt; font-family: 宋体;">更直观）</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US"><br></span><span style="font-size: 9pt; font-family: 宋体;">查看</span><span style="font-size: 9pt; font-family: 宋体;">内存</span><span style="font-size: 9pt; font-family: 宋体;">信息：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">cat /proc/meminfo<br></span><span style="font-size: 9pt; font-family: 宋体;">查看</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">USB</span><span style="font-size: 9pt; font-family: 宋体;">设备：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">cat /proc/bus/</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">usb</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">/devices<br></span><span style="font-size: 9pt; font-family: 宋体;">查看键盘和鼠标</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">:cat /proc/bus/input/devices<br></span><span style="font-size: 9pt; font-family: 宋体;">查看</span><span style="font-size: 9pt; font-family: 宋体;">系统硬盘</span><span style="font-size: 9pt; font-family: 宋体;">信息和使用情况：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">fdisk &amp; disk - l &amp; df<br></span><span style="font-size: 9pt; font-family: 宋体;">查看各设备的中断请求</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">(IRQ):cat /proc/interrupts<br></span><span style="font-size: 9pt; font-family: 宋体;">查看系统体系结构：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">uname -a<br></span><span style="font-size: 9pt; font-family: 宋体;">在</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">LINUX</span><span style="font-size: 9pt; font-family: 宋体;">环境开发驱动程序，首先要探测到新硬件，接下来就是开发驱动程序。</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US"><br></span><span style="font-size: 9pt; font-family: 宋体;">常用命令整理如下：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US"><br></span><span style="font-size: 9pt; font-family: 宋体;">用硬件检测程序</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">kudzu</span><span style="font-size: 9pt; font-family: 宋体;">探测新硬件：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">service kudzu start ( or restart)<br></span><span style="font-size: 9pt; font-family: 宋体;">查看</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">CPU</span><span style="font-size: 9pt; font-family: 宋体;">信息：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">cat /proc/cpuinfo<br></span><span style="font-size: 9pt; font-family: 宋体;">查看板卡信息：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">cat /proc/pci<br></span><span style="font-size: 9pt; font-family: 宋体;">查看</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">PCI</span><span style="font-size: 9pt; font-family: 宋体;">信息：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">lspci (</span><span style="font-size: 9pt; font-family: 宋体;">相比</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">cat /proc/pci</span><span style="font-size: 9pt; font-family: 宋体;">更直观）</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US"><br></span><span style="font-size: 9pt; font-family: 宋体;">查看内存信息：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">cat /proc/meminfo<br></span><span style="font-size: 9pt; font-family: 宋体;">查看</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">USB</span><span style="font-size: 9pt; font-family: 宋体;">设备：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">cat /proc/bus/usb/devices<br></span><span style="font-size: 9pt; font-family: 宋体;">查看键盘和鼠标</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">:cat /proc/bus/input/devices<br></span><span style="font-size: 9pt; font-family: 宋体;">查看系统硬盘信息和使用情况：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">fdisk &amp; disk - l &amp; df<br></span><span style="font-size: 9pt; font-family: 宋体;">查看各设备的中断请求</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">(IRQ):cat /proc/interrupts<br></span><span style="font-size: 9pt; font-family: 宋体;">查看系统体系结构：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">uname &#8211;a</span></p>
<p style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: 9pt; font-family: 宋体;">看看系统认出的盘先：</span><span style="font-size: 9pt; font-family: arial;" lang="EN-US"> cat&nbsp;/proc/partitions</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US"><br>dmidecode</span><span style="font-size: 9pt; font-family: 宋体;">查看硬件信息，包括</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">bios</span><span style="font-size: 9pt; font-family: 宋体;">、</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">cpu</span><span style="font-size: 9pt; font-family: 宋体;">、内存等信息</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US"><br>dmesg | more </span><span style="font-size: 9pt; font-family: 宋体;">查看硬件信息</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US"><br></span><span style="font-size: 9pt; font-family: 宋体;">对于</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">&#8220;/proc&#8221;</span><span style="font-size: 9pt; font-family: 宋体;">中文件可使用文件查看命令浏览其内容，文件中包含系统特定信息：</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US"><br>Cpuinfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 9pt; font-family: 宋体;">主机</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">CPU</span><span style="font-size: 9pt; font-family: 宋体;">信息</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US"><br>Dma&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 9pt; font-family: 宋体;">主机</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">DMA</span><span style="font-size: 9pt; font-family: 宋体;">通道信息</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US"><br>Filesystems&nbsp;&nbsp;&nbsp; </span><span style="font-size: 9pt; font-family: 宋体;">文件系统信息</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US"><br>Interrupts&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 9pt; font-family: 宋体;">主机中断信息</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US"><br>Ioprots&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 9pt; font-family: 宋体;">主机</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US">I/O</span><span style="font-size: 9pt; font-family: 宋体;">端口号信息</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US"><br>Meninfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 9pt; font-family: 宋体;">主机内存信息</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US"><br>Version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Linux</span><span style="font-size: 9pt; font-family: 宋体;">内存版本信息</span><span style="font-size: 9pt; font-family: verdana;" lang="EN-US"></span></p>
<p style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><font face="Times New Roman">&nbsp;</font></span></p>
</div>
</div>
</div><img src ="http://www.cppblog.com/mydriverc/aggbug/98532.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-13 23:10 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/13/98532.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux设备管理文件系统-devfs与sysfs</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/12/98444.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Mon, 12 Oct 2009 15:35:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/12/98444.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98444.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/12/98444.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98444.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98444.html</trackback:ping><description><![CDATA[<p><font size="3" face="Times New Roman">linux下有专门的文件系统用来对设备进行管理，devfs和sysfs就是其中2种。</font></p>
<p><font size="3" face="Times New Roman">在2.6
内核以前一直使用的是devfs，devfs挂载于/dev目录下，提供了一种类似于文件的方法来管理位于/dev目录下的所有设备，我们知道/dev目
录下的每一个文件都对应的是一个设备，至于当前该设备存在与否先且不论，而且这些特殊文件是位于根文件系统上的，在制作文件系统的时候我们就已经建立了这
些设备文件，因此通过操作这些特殊文件，可以实现与内核进行交互。但是devfs文件系统有一些缺点，例如：不确定的设备映射，有时一个设备映射的设备文
件可能不同，例如我的U盘可能对应sda有可能对应sdb；没有足够的主/辅设备号，当设备过多的时候，显然这会成为一个问题；/dev目录下文件太多而
且不能表示当前系统上的实际设备；命名不够灵活，不能任意指定等等。</font></p>
<font size="3" face="Times New Roman">正因为上述这些问题的存在，在linux2.6内核以后，引入了一
个新
的文件系统sysfs，它挂载于/sys目录下，跟devfs一样它也是一个虚拟文件系统，也是用来对系统的设备进行管理的，它把实际连接到系统上的设备
和总线组织成一个分级的文件，用户空间的程序同样可以利用这些信息以实现和内核的交互，该文件系统是当前系统上实际设备树的一个直观反应，它是通过
kobject子系统来建立这个信息的，当一个kobject被创建的时候，对应的文件和目录也就被创建了，位于/sys下的相关目录下，既然每个设备在
sysfs中都有唯一对应的目录，那么也就可以被用户空间读写了。用户空间的工具udev就是利用了sysfs提供的信息来实现所有devfs的功能的，
但不同的是udev运行在用户空间中，而devfs却运行在内核空间，而且udev不存在devfs那些先天的缺陷。很显然，sysfs将是未来发展的方
向。</font><img src ="http://www.cppblog.com/mydriverc/aggbug/98444.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-12 23:35 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/12/98444.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux系统设备管理 </title><link>http://www.cppblog.com/mydriverc/archive/2009/10/12/98443.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Mon, 12 Oct 2009 15:34:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/12/98443.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98443.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/12/98443.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98443.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98443.html</trackback:ping><description><![CDATA[<font id="" font_word="" class="htd">设备管理是操作系统五大管理中最复杂的部分。与Unix系统一样，Linux系统采用设备文件统一管理硬件设备，从而将硬件设备的特性及管理细节对用户隐藏起来，实现用户程序与设备无关性。在Linux系统中，硬件设备分为两种，即块设备和字符设备。<br><br>1.特别文件<br><br>用户是通过文件系统与设备接口的，所有设备都作为特别文件，从而在管理上就具有一些共性。 (1)每个设备都对应文件系统中的一个索引节点，都有一个文件名。设备的文件名一般由两部分构成，第一部分是主设备号，第二部分是次设备号。<br><br>主设备号代表设备的类型，可以惟一地确定设备的驱动程序和界面，如hd表示IDE硬盘，sd表示SCSI硬盘，tty表示终端设备等；次设备号代表同类设备中的序号，如hda表示IDE主硬盘，hdb表示IDE从硬盘等。<br><br>（2）应用程序通常可以通过系统调用open( )打开设备文件，建立起与目标设备的连接。<br><br>（3）对设备的使用类似于对文件的存取。打开设备文件以后，就可以通过read( )、write( )、ioctl( )等文件操作对目标设备进行操作。<br><br>（4）
设备驱动程序都是系统内核的一部分，它们必须为系统内核或它们的子系统提供一个标准的接口。例如，一个终端驱动程序必须为Linux内核提供一个文件
I/O接口；一个SCSI设备驱动程序应该为SCSI子系统提供一个SCSI设备接口，同时SCSI子系统也应为内核提供文件I/O和缓冲区。<br><br>（5）设备驱动程序利用一些标准的内核服务，如内存分配等。另外，大多数Linux设备驱动程序都可以在需要时装入内核，不需要时可以卸载下来。<br><br> <center><img  src="http://unix-cd.com/unixcd12/eWebEditor/UploadFile/2005124211134720.jpg" alt=""></center><br><br> <center>图6 设备驱动分层结构示意图</center>
<div align="left">图6示出设备驱动的分层结构，从中可以看出，处于应用层的进程通过文件描述字fd与已打开文件的file结构相联系。在文件系统层，按照文件系统的操作规则对该文件进行相应处理。<br><br>对于一般文件(即磁盘文件)，要进行空间的映射—从普通文件的逻辑空间映射到设备的逻辑空间，然后在设备驱动层做进一步映射—从设备的逻辑空间映射到物理空间(即设备的物理地址空间)，进而驱动底层物理设备工作。<br><br>对于设备文件，则文件的逻辑空间通常就等价于设备的逻辑空间，然后从设备的逻辑空间映射到设备的物理空间，再驱动底层的物理设备工作。<br><br>2.设备驱动程序和内核之间的接口<br><br>Linux系统和设备驱动程序之间使用标准的交互接口。无论是字符设备、块设备还是网络设备的驱动程序，当内核请求它们提供服务时，都使用同样的接口。<br><br>Linux
提供了一种全新的机制，就是&#8220;可安装模块&#8221;。可安装模块是可以在系统运行时动态地安装和拆卸的内核模块。利用这个机制，可以根据需要在不必对内核重新编译
连接的条件下，将可安装模块动态插入运行中的内核，成为其中一个有机组成部分，或者从内核卸载已安装的模块。设备驱动程序或与设备驱动紧密相关的部分(如
文件系统) 都是利用可安装模块实现的。<br><br>在应用程序界面上，利用内核提供的系统调用来实现可安装模块的动态安装和拆卸。但通常情况下，用户是利用系统提供的插入模块工具和移走模块工具来装卸可安装模块。插入模块的工作主要如下：<br><br>(1) 打开要安装的模块，把它读到用户空间。这种&#8220;模块&#8221;就是经过编译但尚未连接的.o文件。<br><br>(2) 必须把模块内涉及对外访问的符号(函数名或变量名)连接到内核，即把这些符号在内核映像中的地址填入该模块需要访问这些符号的指令及数据结构中。<br><br>(3) 在内核创建一个module数据结构，并申请所需的系统空间。<br><br>(4) 最后，把用户空间中完成了连接的模块映像装入内核空间，并在内核中&#8220;登记&#8221;本模块的有关数据结构(如file_operations结构)，其中有指向执行相关操作函数的指针。<br><br>如前所述，Linux系统是一个动态的操作系统。用户根据工作中的需要，会对系统中设备重新配置，如安装新的打印机、卸载老式终端等。这样，每当Linux系统内核初启时，它都要对硬件配置进行检测，很有可能会检测到不同的物理设备，就需要不同的驱动程序。<br><br>在构建系统内核时，可以使用配置脚本将设备驱动程序包含在系统内核中。在系统启动时对这些驱动程序初始化，它们可能未找到所控制的设备，而另外的设备驱动程序可以在需要时作为内核模块装入到系统内核中。<br>为了适应设备驱动程序动态连接的特性，设备驱动程序在其初始化时就在系统内核中进行登记。Linux系统利用设备驱动程序的登记表作为内核与驱动程序接口的一部分，这些表中包括指向有关处理程序的指针和其它信息。<br><br>3.字符设备<br><br>在Linux
系统中，打印机、终端等字符设备都作为字符特别文件出现在用户面前。用户对字符设备的使用就和存取普通文件一样。在应用程序中，使用标准的系统调用来打
开、关闭、读写字符设备。当字符设备初始化时，其设备驱动程序被添加到由device_struct结构组成的chrdevs结构数组中。<br><br>device_struct
结构由两项构成，一个是指向已登记的设备驱动程序名的指针，另一个是指向file_operations结构的指针。而file_operations结
构的成分几乎全是函数指针，分别指向实现文件操作的入口函数。设备的主设备号用来对chrdevs数组进行索引，如图7所示。<br><br> <center><img  src="http://unix-cd.com/unixcd12/eWebEditor/UploadFile/2005124211135373.jpg" alt=""></center><br><br> <center>图7 字符设备驱动程序示意图</center><br><br>前面讲过，每个VFS索引节点都和一系列文件操作相联系，并且这些文件操作随索引节点所代表的文件类型不同而不同。每当一个VFS索引节点所代表的字符设备文件创建时，它的有关文件的操作就设置为默认的字符设备操作。<br><br>默认的文件操作只包含一个打开文件的操作。当打开一个代表字符设备的特别文件以后，就得到相应的VFS索引节点，其中包括该设备的主设备号和次设备号。<br><br>利用主设备号就可以检索chrdevs数组，进而可以找到有关此设备的各种文件操作。这样，应用程序中的文件操作就会映射到字符设备的文件操作调用中。<br><br>4.块设备<br><br>对块设备的存取和对文件的存取方式一样，其实现机制也和字符设备使用的机制相同。Linux系统中有一个名为blkdevs的结构数组，它描述了一系列在系统中登记的块设备。</div>
<div align="left">数组blkdevs也使用设备的主设备号作为索引，其元素类型是device_struct结构。该结构中包括指向已登记的设备驱动程序名的指针和指向block_device_operations结构的指针。<br><br>在block_device_operations结构中包含指向有关操作的函数指针。所以，该结构就是连接抽象的块设备操作与具体块设备类型的操作之间的枢纽。<br><br>与字符设备不一样，块设备有几种类型，例如SCSI设备和IDE设备。每类块设备都在Linux系统内核中登记，并向内核提供自己的文件操作。<br><br>为了把各种块设备的操作请求队列有效地组织起来，内核中设置了一个结构数组blk_dev，该数组中的元素类型是blk_dev_struct结构。这个结构由三个成分组成，其主体是执行操作的请求队列request_queue，还有一个函数指针queue。<br><br>当
这个指针不为0时，就调用这个函数来找到具体设备的请求队列。这是考虑到多个设备可能具有同一主设备号，该指针在设备初始化时被设置好。通常当它不为0
时，还要使用该结构中的另一个指针data，用来提供辅助性信息，帮助该函数找到特定设备的请求队列。每一个请求数据结构都代表一个来自缓冲区的请求。<br><br>每当缓冲区要和一个登记过的块设备交换数据，它都会在blk_dev_struct中添加一个请求数据结构，如图8所示。<br><br> <center><img  src="http://unix-cd.com/unixcd12/eWebEditor/UploadFile/2005124211135594.jpg" alt=""></center><br><br> <center>图8 块设备驱动程序数据结构示意图</center><br><br>每
一个请求都有一个指针指向一个或多个buffer_head数
据结构，而该结构都是一个读写数据块的请求。每一个请求结构都在一个静态链表all_requests中。若干请求是添加到一个空的请求链表中，则调用设
备驱动程序的请求函数，开始处理该请求队列。否则，设备驱动程序就简单地处理请求队列中的每一个请求。<br><br>当设备驱动程序完成了一个请求后，就把buffer_head结构从request结构中移走，并标记buffer_head结构已更新，同时解锁，这样，就可以唤醒相应的等待进程。</div>
</font><img src ="http://www.cppblog.com/mydriverc/aggbug/98443.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-12 23:34 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/12/98443.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>/etc/inittab详解</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/12/98439.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Mon, 12 Oct 2009 15:19:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/12/98439.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98439.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/12/98439.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98439.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98439.html</trackback:ping><description><![CDATA[init的进程号是1，从这一点就能看出，init进程是系统所有进程的起点，Linux在完成核内引导以后，就开始运行init程式，。<br>init程式需 要读取设置文件/etc/inittab。inittab是个不可执行的文本文件，他有若干行指令所组成。在Redhat系统中，inittab的内容 如下所示(以&#8220;###"开始的中注释为笔者增加的)：<br>　　<br>　　#<br>　　# inittab　　　 This file describes how the INIT process should set up<br>　　#　　　　　　　 the system in a certain run-level.<br>　　#<br>　　# Author:　　　 Miquel van Smoorenburg, <br>　　#　　　　　　　 Modified for RHS Linux by Marc Ewing and Donnie Barnes<br>　　#<br>　　<br>　　# Default runlevel. The runlevels used by RHS are:<br>　　#　 0 - halt (Do NOT set initdefault to this)<br>　　#　 1 - Single user mode<br>　　#　 2 - Multiuser, without NFS (The same as 3, if you do not havenetworking)<br>　　#　 3 - Full multiuser mode<br>　　#　 4 - unused<br>　　#　 5 - X11<br>　　#　 6 - reboot (Do NOT set initdefault to this)<br>　　#<br>/*<br>理解Runlevel<br>
runlevel用来表示在init进程结束之后的系统状态，在系统的硬件中没有固定的信息来表示runlevel，他纯粹是一种软件结构。init和
inittab是runlevel影响系统状态的唯一原因。在上述例子中inittab文件起始阶段的注释主要用来描述runlevel：<br>    Runlevel 0是让init关闭所有进程并终止系统。<br>    Runlevel 1是用来将系统转到单用户模式，单用户模式只能有系统管理员进入，在该模式下处理那些在有登录用户的情况下不能进行更改的文件，改runlevel的编号1也能用S代替。<br>    Runlevel 2是允许系统进入多用户的模式，但并不支持文件共享，这种模式非常少应用。<br>    Runlevel 3是最常用的运行模式，主要用来提供真正的多用户模式，也是多数服务器的缺省模式。<br>    Runlevel 4一般不被系统使用，用户能设计自己的系统状态并将其应用到runlevel 4阶段，尽管非常少使用，但使用该系统能实现一些特定的登录请求。<br>    Runlevel 5是将系统初始化为专用的X Window终端。对功能强大的Linux系统来说，这并不是好的选择，但用户如果需要这样，也能通过在runlevel启动来实现该方案。<br>    Runlevel 6是关闭所有运行的进程并重新启动系统。*/<br>　　###表示当前缺省运行级别为5(initdefault)；<br>　　id:5:initdefault:   /*启动后进入图像界面,设为3则进入字符终端界面*/<br>　　<br>　　###启动时自动执行/etc/rc.d/rc.sysinit脚本(sysinit)<br>/*<br>在inittab文件中以#开头的所有行都是注释行。注释行有助于用户理解inittab文件，inittab文件中的值都是如下格式：<br>    label:runlevel:action:process<br>    label是1~4个字符的标签，用来标示输入的值。一些系统只支持2个字符的标签。鉴于此原因，多数人都将标签字符的个数限制在2个以内。该标签能是任意字符构成的字符串，但实际上，某些特定的标签是常用的，在Red Hat Linux中使用的标签是：<br>代码:<br>    id 用来定义缺省的init运行的级别<br>    si 是系统初始化的进程<br>    ln 其中的n从1~6,指明该进程能使用的runlevel的级别<br>    ud 是升级进程<br>    ca 指明当按下Ctrl+Alt+Del时运行的进程<br>    pf 指当UPS表明断电时运行的进程<br>    pr 是在系统真正关闭之前，UPS发出电源恢复的信号时需要运行的进程<br>    x  是将系统转入X终端时需要运行的进程<br>    runlevel字段指定runlevel的级别。能指定多个runlevel级别，也能不为runlevel字段指定特定的值。<br>    action字段定义了该进程应该运行在何种状态下：<br>    代码:<br>    boot        在系统启动时运行，忽略runlevel<br>    bootwait    在系统启动时运行，init等待进程完成。忽略runlevel<br>    ctrlaltdel    当Ctrl+Alt+Del三个键同时按下时运行，把SIGINT信号发送给init。忽略    runlevel<br>    initdefault    不要执行这个进程，他用于设置默认runlevel<br>    kbrequest    当init从键盘中收到信号时运行。这里需求键盘组合符合KeyBoardSigral(参见/usr/share/doc/kbd-*关于键盘组合的文件)<br>    off        禁止进入，因此该进程不运行<br>    on
<div class="ns_content"><wbr>ce        每一个runlevel级别运行一次<br>    on<wbr>demand    当系统指定特定的运行级别A、B、C时运行<br>    powerfail    当init收到SIGPWR信号时运行<br>    powerokwait    当收到SIGPWD信号且/etc/文件中的电源状态包含OK时运行<br>    powerwait    当收到SIGPWD信号，并且init等待进程结束时运行<br>    respawn        不管何时终止都重新启动进程<br>    sysinit        在运行boot或bootwait进程之前运行<br>    wait        运行进程等待输入运行模式<br>
process字段包含init执行的进程，该进程采用的格式和在命令行下运行该进程的格式相同，因此process字段都以该进程的名字开头，紧跟着是
运行时，紧跟着是运行时要传递给该进程的参数。比如/sbin/shutdown -t3 -r
now，该进程在按下Ctrl+Alt+Del时执行，在命令行下也能直接输入来重新启动系统。<br>    特别目的的记录<br>        仔细学习例子文件，学习应用其中关于inittab的语法格式。该文件的大多数内容都能忽略，因为超过一半的内容都是注释，剩余的一些文件内容主要是用来实现某些特别的功能：<br>    id 的值表明缺省的runlevel是3。<br>    ud 的值能唤醒/sbin/update进程，该进程为保持磁盘的完整性，将在对磁盘进行I/O操作之前清空整个I/O缓冲区。<br>    pf、pr和ca的值只被特定的中断所调用。<br>    如果系统是专用的X终端，则只需x的输入值。<br>    getty进程来提供虚拟终端设备的服务，例如：<br>    3:2345:respawn:/sbin/mingetty tty3<br>
标签字段的值是3,3是设备tty3的数字后缀,tty3和相应的进程相关联，该getty进程能启动的runlevel是2、3、4和5,当该进程终
止时，init马上就重新启动他。启动进程的路径名是/sbin/mingetty，该进程是实现虚拟终端支持的最小版本的getty，为tty3提供启
动虚拟设备的进程。<br>    si::sysinit:/etc/rc.d/rc.sysinit<br>
该值告诉init程式运行/etc/rc.d/rc.sysinit脚本文件来初始化系统，该脚本文件和所有启动的脚本类似，他只是个包含Linux的
shell命令的可执行文件，注意输入的字符串必须包括该脚本的完整路径。不同版本的Linux存放该脚本的位置也不相同，但不用刻意去记忆这些位置，只
需查看/etc/inittab文件即可，该文件中包含启动脚本文件的确切位置。*/<br>　　# System initialization.<br>　　si::sysinit:/etc/rc.d/rc.sysinit<br>　　<br>　　l0:0:wait:/etc/rc.d/rc 0<br>　　l1:1:wait:/etc/rc.d/rc 1<br>　　l2:2:wait:/etc/rc.d/rc 2<br>　　l3:3:wait:/etc/rc.d/rc 3<br>　　l4:4:wait:/etc/rc.d/rc 4<br>　　###当运行级别为5时，以5为参数运行/etc/rc.d/rc脚本，init将等待其返回(wait)<br>　　l5:5:wait:/etc/rc.d/rc 5<br>　　l6:6:wait:/etc/rc.d/rc 6<br>　　<br>　　###在启动过程中允许按CTRL-ALT-DELETE重启系统<br>　　# Trap CTRL-ALT-DELETE<br>　　ca::ctrlaltdel:/sbin/shutdown -t3 -r now<br>　　<br>　　# When our UPS tells us power has failed, assume we have a few minutes<br>　　# of power left.　Schedule a shutdown for 2 minutes from now.<br>　　# This does, of course, assume you have powerd installed and your<br>　　# UPS connected and working correctly.<br>　　pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"<br>　　<br>　　# If power was restored before the shutdown kicked in, cancel it.<br>　　pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"<br>　　<br>　　###在2、3、4、5级别上以ttyX为参数执行/sbin/mingetty程式，打开ttyX终端用于用户登录，<br>　　###如果进程退出则再次运行mingetty程式(respawn)<br>　　# Run gettys in standard runlevels<br>　　1:2345:respawn:/sbin/mingetty tty1<br>　　2:2345:respawn:/sbin/mingetty tty2<br>　　3:2345:respawn:/sbin/mingetty tty3<br>　　4:2345:respawn:/sbin/mingetty tty4<br>　　5:2345:respawn:/sbin/mingetty tty5<br>　　6:2345:respawn:/sbin/mingetty tty6<br>　　<br>　　###在5级别上运行xdm程式，提供xdm图像方式登录界面，并在退出时重新执行(respawn)<br>　　# Run xdm in runlevel 5<br>　　x:5:respawn:/etc/X11/prefdm -nodaemon<br>　　<br>　　以上面的inittab文件为例，来说明一下inittab的格式。其中以#开始的行是注释行，除了注释行之外，每一行都有以下格式：<br>　　<br>　　id:runlevel:action:process<br>　　<br>　　对上面各项的周详解释如下：<br>　　<br>　　1. id<br>　　<br>　　id是指入口标识符，他是个字符串，对于getty或mingetty等其他login程式项，需求id和tty的编号相同，否则getty程式将不能正常工作。<br>　　<br>　　2. runlevel<br>　　<br>
runlevel是init所处于的运行级别的标识，一般使用0－6及S或s。0、1、6运行级别被系统保留：其中0作为shutdown动作，1作
为重启至单用户模式，6为重启；S和s意义相同，表示单用户模式，且无需inittab文件，因此也不在inittab中出现，实际上，进入单用户模式
时，init直接在控制台（/dev/console）上运行/sbin/sulogin。在一般的系统实现中，都使用了2、3、4、5几个级别，在
Redhat系统中，2表示无NFS支持的多用户模式，3表示完全多用户模式（也是最常用的级别），4保留给用户自定义，5表示XDM图像登录方式。7－
9级别也是能使用的，传统的Unix系统没有定义这几个级别。runlevel能是并列的多个值，以匹配多个运行级别，对大多数action来说，仅
当runlevel和当前运行级别匹配成功才会执行。<br>　　<br>　　3. action<br>　　<br>　　action是描述其后的process的运行方式的。action可取的值包括：initdefault、sysinit、boot、bootwait等：<br>　　<br>
initdefault是个特别的action值，用于标识缺省的启动级别；当init由核心激活以后，他将读取inittab中的
initdefault项，取得其中的runlevel，并作为当前的运行级别。如果没有inittab文件，或其中没有initdefault项，
init将在控制台上请求输入runlevel。<br>　　<br>　　sysinit、boot、bootwait等action将在系统启动时无条件运行，而忽略其中的runlevel。<br>　　<br>　　其余的action（不含initdefault）都和某个runlevel相关。各个action的定义在inittab的man手册中有周详的描述。<br>　　<br>　　4. process<br>　　<br>　　process为具体的执行程式。程式后面能带参数。<br>　　<br>　　第三部分：系统初始化<br>　　<br>　　在init的设置文件中有这么一行：<br>　　<br>　　si::sysinit:/etc/rc.d/rc.sysinit<br>　　<br>　　他调用执行了/etc/rc.d/rc.sysinit，而rc.sysinit是个bash shell的脚本，他主要<br>在init的设置文件中有这么一行：<br>si::sysinit:/etc/rc.d/rc.sysinit<br>他
调用执行了/etc/rc.d/rc.sysinit，而rc.sysinit是个bash
shell的脚本，他主要是完成一些系统初始化的工作，rc.sysinit是每一个运行级别都要首先运行的重要脚本。他主要完成的工作有：激活交换分
区，检查磁盘，加载硬件模块及其他一些需要优先执行任务。<br>rc.sysinit约有850多行，不过每个单一的功能还是比较简单，而且带有注释，建议有兴趣的用户能自行阅读自己机器上的该文件，以了解系统初始化所周详情况。由于此文件较长，所以不在本文中列出来，也不做具体的介绍。<br>当rc.sysinit程式执行完毕后，将返回init继续下一步。<br>第四部分：启动对应运行级别的守护进程<br>在rc.sysinit执行后，将返回init继续其他的动作，通常接下来会执行到/etc/rc.d/rc程式。以运行级别5为例，init将执行设置文件inittab中的以下这行：<br>l5:5:wait:/etc/rc.d/rc 5<br>这
一行表示以5为参数运行/etc/rc.d/rc，/etc/rc.d/rc是个Shell脚本，他接受5作为参数，去执行/etc/rc.d
/rc5.d/目录下的所有的rc启动脚本，/etc/rc.d/rc5.d/目录中的这些启动脚本实际上都是一些链接文件，而不是真正的rc启动脚本，
真正的rc启动脚本实际上都是放在/etc/rc.d/init.d/目录下。而这些rc启动脚本有着类似的用法，他们一般能接受start、stop、
restart、status等参数。<br>/etc/rc.d/rc5.d/中的rc启动脚本通常是K或S开头的链接文件，对于以以S开头的启动脚
本，将以start参数来运行。而如果发现存在相应的脚本也存在K打头的链接，而且已处于运行态了(以/var/lock/subsys/下的文件作为标
志)，则将首先以stop为参数停止这些已启动了的守护进程，然后再重新运行。这样做是为了确保是当init改动运行级别时，所有相关的守护进程都将重
启。<br>至于在每个运行级中将运行哪些守护进程，用户能通过chkconfig或setup中的"System Services"来自行设定。常见的守护进程有：<br>amd：自动安装NFS守护进程<br>　　apmd:高级电源管理守护进程<br>　　arpwatch：记录日志并构建一个在LAN接口上看到的以太网地址和IP地址对数据库<br>　　autofs：自动安装管理进程automount，和NFS相关，依赖于NIS<br>　　crond：Linux下的计划任务的守护进程<br>　　named：DNS服务器<br>　　netfs：安装NFS、Samba和NetWare网络文件系统<br>　　network：激活已设置网络接口的脚本程式<br>　　nfs：打开NFS服务<br>　　portmap：RPC portmap管理器，他管理基于RPC服务的连接<br>　　sendmail：邮件服务器sendmail<br>　　smb：Samba文件共享/打印服务<br>　　syslog：一个让系统引导时起动syslog和klogd系统日志守候进程的脚本<br>　　xfs：X Window字型服务器，为本地和远程X服务器提供字型集<br>　　Xinetd：支持多种网络服务的核心守护进程，能管理wuftp、sshd、telnet等服务<br>这些守护进程也启动完成了，rc程式也就执行完了，然后又将返回init继续下一步。<br>第五部分：建立终端<br>rc执行完毕后，返回init。这时基本系统环境已设置好了，各种守护进程也已启动了。init接下来会打开6个终端，以便用户登录系统。通过按Alt+Fn(n对应1-6)能在这6个终端中转换。在inittab中的以下6行就是定义了6个终端：<br>1:2345:respawn:/sbin/mingetty tty1<br>　　2:2345:respawn:/sbin/mingetty tty2<br>　　3:2345:respawn:/sbin/mingetty tty3<br>　　4:2345:respawn:/sbin/mingetty tty4<br>　　5:2345:respawn:/sbin/mingetty tty5<br>　　6:2345:respawn:/sbin/mingetty tty6<br>从
上面能看出在2、3、4、5的运行级别中都将以respawn方式运行mingetty程式，mingetty程式能打开终端、设置模式。同时他会显示一
个文本登录界面，这个界面就是我们经常看到的登录界面，在这个登录界面中会提示用户输入用户名，而用户输入的用户将作为参数传给login程式来验证用户
的身份。<br>第六部分：登录系统，启动完成<br>对于运行级别为5的图像方式用户来说，他们的登录是通过一个图像化的登录界面。登录成功后能直接进入KDE、Gnome等窗口管理器。而本文主要讲的还是文本方式登录的情况：<br>当我们看到mingetty的登录界面时，我们就能输入用户名和密码来登录系统了。<br>
Linux的账号验证程式是login，login会接收mingetty传来的用户名作为用户名参数。然后login会对用户名进行分析：如果用户名
不是root，且存在/etc/nologin文件，login将输出nologin文件的内容，然后退出。这通常用来系统维护时防止非root用户登
录。只有/etc/securetty中登记了的终端才允许root用户登录，如果不存在这个文件，则root能在所有终端上登录。/etc
/usertty文件用于对用户作出附加访问限制，如果不存在这个文件，则没有其他限制。<br>在分析完用户名后，login将搜索/etc/passwd及/etc/shadow来验证密码及设置账户的其他信息，比如：主目录是什么、使用何种shell。如果没有指定主目录，将默认为根目录；如果没有指定shell，将默认为/bin/bash。<br>login
程式成功后，会向对应的终端在输出最近一次登录的信息(在/var/log/lastlog中有记录)，并检查用户是否有新邮件(在/usr/spool
/mail/的对应用户名目录下)。然后开始设置各种环境变量：对于bash来说，系统首先寻找/etc/profile脚本文件，并执行他；然后如果用
户的主目录中存在.bash_profile文件，就执行他，在这些文件中又可能调用了其他设置文件，所有的设置文件执行后后，各种环境变量也设好了，这
时会出现大家熟悉的命令行提示符，到此整个启动过程就结束了。<br>希望通过上面对Linux启动过程的剖析能帮助那些想深入学习Linux用户建立一个相关Linux启动过程的清晰概念，进而能进一步研究Linux接下来是怎么工作的。</div><img src ="http://www.cppblog.com/mydriverc/aggbug/98439.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-12 23:19 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/12/98439.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux进入系统直接就是x界面，怎么才能进入命令行模式？  </title><link>http://www.cppblog.com/mydriverc/archive/2009/10/12/98437.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Mon, 12 Oct 2009 15:09:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/12/98437.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98437.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/12/98437.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98437.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98437.html</trackback:ping><description><![CDATA[<font size="3">$gedit &nbsp; /etc/inittab&nbsp;&nbsp;&nbsp;<br>&nbsp;把id:5:initdefault中的5改为3</font>
<p><font size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0：停机（记住不要把initdefault 设置为0，因为这样会使Linux无法启动 ）<br>　　1：单用户模式，就像Win9X下的安全模式。<br>　　2：多用户，但是没有 NFS 。<br>　　3：完全多用户模式，标准的运行级。<br>　　4：一般不用，在一些特殊情况下可以用它来做一些事情。<br>　　5：X11，即进到 X-Window 系统。<br>　　6：重新启动 （记住不要把initdefault 设置为6，因为这样会使Linux不断地重新启动）。</font></p>
<p><font size="3">　　其中运行级3就是我们要进入的标准Console字符界面模式</font></p><img src ="http://www.cppblog.com/mydriverc/aggbug/98437.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-12 23:09 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/12/98437.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>init进程及inittab文件</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/09/98208.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Fri, 09 Oct 2009 15:27:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/09/98208.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98208.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/09/98208.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98208.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98208.html</trackback:ping><description><![CDATA[摘自《Linux Network Servers 24 seven》<br>
init进程<br>
<br>
init的进程号为1,是所有进程的父进程，内核初始化完毕之后，init程序开始运行。其他软件也同时开始运行。init程序通过/etc/inittab文件进行配置。inittab文件的内容如下：<br>
<div style="margin: 5px 20px 20px;">
<div class="smallfont" style="margin-bottom: 2px;">代码:</div>
<hr><code dir="ltr" style="margin: 0px;">#<br>
# inittab&nbsp; &nbsp; &nbsp;  This file describes how the INIT process should set up<br>
#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  the system in a certain run-level.<br>
#<br>
# Author:&nbsp; &nbsp; &nbsp;  Miquel van Smoorenburg, &lt;miquels@drinkel.nl.mugnet.org&gt;<br>
#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Modified for RHS Linux by Marc Ewing and Donnie Barnes<br>
#<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br>
# Default runlevel. The runlevels used by RHS are:<br>
#&nbsp;  0 - halt (Do NOT set initdefault to this)<br>
#&nbsp;  1 - Single user mode<br>
#&nbsp;  2 - Multiuser, without NFS (The same as 3, if you do not have networking)<br>
#&nbsp;  3 - Full multiuser mode<br>
#&nbsp;  4 - unused<br>
#&nbsp;  5 - X11<br>
#&nbsp;  6 - reboot (Do NOT set initdefault to this)<br>
#<br>
id:3:initdefault:<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br>
# System initialization.<br>
si::sysinit:/etc/rc.d/rc.sysinit<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br>
l0:0:wait:/etc/rc.d/rc 0<br>
l1:1:wait:/etc/rc.d/rc 1<br>
l2:2:wait:/etc/rc.d/rc 2<br>
l3:3:wait:/etc/rc.d/rc 3<br>
l4:4:wait:/etc/rc.d/rc 4<br>
l5:5:wait:/etc/rc.d/rc 5<br>
l6:6:wait:/etc/rc.d/rc 6<br>
<br>
# Things to run in every runlevel<br>
ud::once:/sbin/update<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br>
# Trap CTRL-ALT-DELETE<br>
ca::ctrlaltdel:/sbin/shutdown -t3 -r now<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br>
# When our UPS tells us power has failed, assume we have a few minutes<br>
# of power left.&nbsp; Schedule a shutdown for 2 minutes from now.<br>
# This does, of course, assume you have powerd installed and your<br>
# UPS connected and working correctly.<br>
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br>
# If power was restored before the shutdown kicked in, cancel it.<br>
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"<br>
<br>
<br>
# If power was restored before the shutdown kicked in, cancel it.<br>
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br>
# Run gettys in standard runlevels<br>
1:2345:respawn:/sbin/mingetty tty1<br>
2:2345:respawn:/sbin/mingetty tty2<br>
3:2345:respawn:/sbin/mingetty tty3<br>
4:2345:respawn:/sbin/mingetty tty4<br>
5:2345:respawn:/sbin/mingetty tty5<br>
6:2345:respawn:/sbin/mingetty tty6<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br>
# Run xdm in runlevel 5<br>
x:5:respawn:/etc/X11/prefdm -nodaemon</code><hr>
</div>
<br>
注意：案例文件的注释是经过编辑的，为的是保持书面的一致性。<br>
<font color="red"><br>
理解Runlevel<br>
</font><br>
runlevel用来表示在init进程结束之后的系统状态，在系统的硬件中没有固定的信息来表示runlevel，它纯粹是一种软件结构。init和
inittab是runlevel影响系统状态的唯一原因。在上述例子中inittab文件起始阶段的注释主要用来描述runlevel：<br>
<br>
Runlevel 0是让init关闭所有进程并终止系统。<br>
Runlevel 1是用来将系统转到单用户模式，单用户模式只能有系统管理员进入，在该模式下处理那些在有登录用户的情况下不能进行更改的文件，改runlevel的编号1也可以用S代替。<br>
Runlevel 2是允许系统进入多用户的模式，但并不支持文件共享，这种模式很少应用。<br>
Runlevel 3是最常用的运行模式，主要用来提供真正的多用户模式，也是多数服务器的缺省模式。<br>
Runlevel 4一般不被系统使用，用户可以设计自己的系统状态并将其应用到runlevel 4阶段，尽管很少使用，但使用该系统可以实现一些特定的登录请求。<br>
Runlevel 5是将系统初始化为专用的X Window终端。对功能强大的Linux系统来说，这并不是好的选择，但用户如果需要这样，也可以通过在runlevel启动来实现该方案。<br>
Runlevel 6是关闭所有运行的进程并重新启动系统。<br>
<br>
在inittab文件中以#开头的所有行都是注释行。注释行有助于用户理解inittab文件，inittab文件中的值都是如下格式：<br>
<font color="red"><br>
label:runlevel:action:process<br>
</font><br>
<font color="red">label</font>是1~4个字符的标签，用来标示输入的值。一些系统只支持2个字符的标签。鉴于此原因，多数人都将标签字符的个数限制在2个以内。该标签可以是任意字符构成的字符串，但实际上，某些特定的标签是常用的，在Red Hat Linux中使用的标签是：<br>
<div style="margin: 5px 20px 20px;">
<div class="smallfont" style="margin-bottom: 2px;">代码:</div>
<hr><code dir="ltr" style="margin: 0px;">id 用来定义缺省的init运行的级别<br>
si 是系统初始化的进程<br>
ln 其中的n从1~6,指明该进程可以使用的runlevel的级别<br>
ud 是升级进程<br>
ca 指明当按下Ctrl+Alt+Del是运行的进程<br>
pf 指当UPS表明断电时运行的进程<br>
pr 是在系统真正关闭之前，UPS发出电源恢复的信号时需要运行的进程<br>
x&nbsp; 是将系统转入X终端时需要运行的进程</code><hr>
</div>
<font color="red">runlevel</font>字段指定runlevel的级别。可以指定多个runlevel级别，也可以不为runlevel字段指定特定的值。<br>
<br>
<font color="red">action</font>字段定义了该进程应该运行在何种状态下：<br>
<div style="margin: 5px 20px 20px;">
<div class="smallfont" style="margin-bottom: 2px;">代码:</div>
<hr><code dir="ltr" style="margin: 0px;">boot&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 在系统启动时运行，忽略runlevel<br>
bootwait&nbsp; &nbsp; &nbsp; &nbsp; 在系统启动时运行，init等待进程完成。忽略runlevel<br>
ctrlaltdel&nbsp; &nbsp; &nbsp; &nbsp; 当Ctrl+Alt+Del三个键同时按下时运行，把SIGINT信号发送给init。忽略runlevel<br>
initdefault&nbsp; &nbsp; &nbsp; &nbsp; 不要执行这个进程，它用于设置默认runlevel<br>
kbrequest&nbsp; &nbsp; &nbsp; &nbsp; 当init从键盘中收到信号时运行。这里要求键盘组合符合KeyBoardSigral(参见/usr/share/doc/kbd-*关于键盘组合的文档)<br>
off&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 禁止进入，因此该进程不运行<br>
once&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 每一个runlevel级别运行一次<br>
ondemand&nbsp; &nbsp; &nbsp; &nbsp; 当系统指定特定的运行级别A、B、C时运行<br>
powerfail&nbsp; &nbsp; &nbsp; &nbsp; 当init收到SIGPWR信号时运行<br>
powerokwait&nbsp; &nbsp; &nbsp; &nbsp; 当收到SIGPWD信号且/etc/文件中的电源状态包含OK时运行<br>
powerwait&nbsp; &nbsp; &nbsp; &nbsp; 当收到SIGPWD信号，并且init等待进程结束时运行<br>
respawn&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 不管何时终止都重新启动进程<br>
sysinit&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 在运行boot或bootwait进程之前运行<br>
wait&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 运行进程等待输入运行模式</code><hr>
</div>
<font color="red">process</font>字段包含init执行的进程，该进程采用的格式与在命令行下运行该进程的
格式一样，因此process字段都以该进程的名字开头，紧跟着是运行时，紧跟着是运行时要传递给该进程的参数。比如/sbin/shutdown
-t3 -r now，该进程在按下Ctrl+Alt+Del时执行，在命令行下也可以直接输入来重新启动系统。<br>
<font color="red"><br>
特殊目的的记录<br>
</font><br>
仔细学习例子文件，学习应用其中关于inittab的语法格式。该文件的大多数内容都可以忽略，因为超过一半的内容都是注释，剩余的一些文件内容主要是用来实现某些特殊的功能：<br>
<br>
id 的值表明缺省的runlevel是3。<br>
ud 的值可以唤醒/sbin/update进程，该进程为保持磁盘的完整性，将在对磁盘进行I/O操作之前清空整个I/O缓冲区。<br>
pf、pr和ca的值只被特定的中断所调用。<br>
如果系统是专用的X终端，则只需x的输入值。<br>
<br>
getty进程来提供虚拟终端设备的服务，例如：<br>
<font color="red"><br>
3:2345:respawn:/sbin/mingetty tty3<br>
</font><br>
标签字段的值是3,3是设备tty3的数字后缀,tty3与相应的进程相关联，该getty进程可以启动的runlevel是2、3、4和5,当该进程终
止时，init马上就重新启动它。启动进程的路径名是/sbin/mingetty，该进程是实现虚拟终端支持的最小版本的getty，为tty3提供启
动虚拟设备的进程。<br>
<font color="red"><br>
si::sysinit:/etc/rc.d/rc.sysinit<br>
</font><br>
该值告诉init程序运行/etc/rc.d/rc.sysinit脚本文件来初始化系统，该脚本文件与所有启动的脚本类似，它只是一个包含Linux的
shell命令的可执行文件，注意输入的字符串必须包括该脚本的完整路径。不同版本的Linux存放该脚本的位置也不相同，但不用刻意去记忆这些位置，只
需查看/etc/inittab文件即可，该文件中包含启动脚本文件的确切位置。<br>
<font color="red"><br>
l3:3:wait:/etc/rc.d/rc 3<br>
</font><br>
该行表示要启动所有由runlevel
3定义的支持多用户的进程的服务，标签l3是级别3的标志，在与运行level3相关的inittab文件之前init程序将一直处于等待状态，直到启动
脚本终止，init将执行/etc/rc.d/rc，并向该脚本传递命令行的参数为3。<img src ="http://www.cppblog.com/mydriverc/aggbug/98208.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-09 23:27 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/09/98208.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>/etc/inputrc</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/09/98204.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Fri, 09 Oct 2009 14:48:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/09/98204.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98204.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/09/98204.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98204.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98204.html</trackback:ping><description><![CDATA[<p>Inputrc 用来处理键盘映射表。这个文件在启动的时候被一个bash和其他shell使用的库，readline，调用。</p>
<p>阅读<tt class="filename"><font face="新宋体">info bash</font></tt> -- 小节: Readline Init file 和<tt class="filename"><font face="新宋体">info readline</font></tt>可以获得更多信息。这个rc文件可以作很多事情。</p>
<p>接下来的是一个基本的<tt class="filename"><font face="新宋体">/etc/inputrc</font></tt>，其中有对各个配置参数的解释。</p>
<p>请注意这些注释<em>不能</em>和<tt class="filename"><font face="新宋体">inputrc</font></tt>中的命令处作在同一行。</p>
<p>
<table bgcolor="#e0e0e0" border="0" width="100%">
    <tbody>
        <tr>
            <td>
            <pre class="screen"># /etc/inputrc的开始<br><br># 确认我们不会在同一行中输出所有的东西。<br>set horizontal-scroll-mode Off<br><br># 开启8比特输入<br>set meta-flag On<br>set input-meta On<br><br># 禁止对第8个比特过滤<br>set convert-meta Off<br><br># 在显示时保存第8个比特<br>set output-meta On<br><br># 关闭可视和声音提示<br>set bell-style none<br><br># 下面的内容给出了在readline<br># 函数第一部分中包括的换码符序列的值<br><br>"\eOd": backward-word<br>"\eOc": forward-word<br><br># 在控制台使用<br>"\e[1~": beginning-of-line<br>"\e[4~": end-of-line<br>"\e[5~": beginning-of-history<br>"\e[6~": end-of-history<br>"\e[3~": delete-char<br>"\e[2~": quoted-insert<br><br># xterm使用<br>"\eOH": beginning-of-line<br>"\eOF": end-of-line<br><br># /etc/inputrc结束<br></pre>
            </td>
        </tr>
    </tbody>
</table>
</p>
<p>全局的设定值包含在 <tt class="filename"><font face="新宋体">/etc/inputrc</font></tt>中。每个用户自己的值设定于<tt class="filename"><font face="新宋体">~/.inputrc</font></tt>。 <tt class="filename"><font face="新宋体">~/.inputrc</font></tt> 若存在，则会忽略全局设定值。前面bash设定中缺省调用 <tt class="filename"><font face="新宋体">/etc/inputrc</font></tt> 如果你想让系统同时使用两个设定，可以把一个 <tt class="filename"><font face="新宋体">.inputrc</font></tt>放到<tt class="filename"><font face="新宋体">/etc/skel</font></tt> 中给每一个新建立的用户使用。</p>
<p><br></p>
<p><br></p>
<p><br></p>
<p>~/.inputrc <br>　　"\M-H , \C-H" : "cd $HOME" <br>　　"\M-H ; \C-H" : "cd $HOME" <br>　　"\M-H + \C-H" : "cd $HOME" <br>　　"\M-H &amp; \C-H" : "cd $HOME" <br>　　.... <br>　　<br>　　Any idea is greatly appreciated! 3KU very much ! <br>　　<br>　　先用cat查看组合热键的ASCII字符： <br>　　# cat <br>　　&lt;按下热键，如：Ctrl-Alt-H&gt; <br>　　看到了什么？ ^[^H 对不对？ <br>　　按&lt;Ctrl-D&gt;退出 <br>　　同理可以得知其他组合热键对应的ASCII字符， 有一些组合热键像Ctrl＋Alt＋D/Q/Z/C/S/M/J/U/I/E好像不能使用，不过没关系，可用的热键有15个左右 <br>　　<br>　　然后修改/etc/inputrc 或 ~/.inputrc，向里面添加组合热键的宏定义，偶的如下： <br>　　<br>　　"^[^G":"gaim &amp; &amp;&gt;/dev/null &amp;&amp; disown\C-M" <br>
#按Ctrl-Alt-g在当前shell打开gaim, 并脱离该shell独立运行，即：即使你退出了该shell，
gaim也不会关闭字符输入方法: 在vi的插入模式下， ^[是先按Ctrl-V, 然后按ESC，[^G是先按Ctrl-v,
然后按Ctrl-H，其他的与此类似 <br>　　<br>　　"^[^H":"vi /etc/httpd/conf/httpd.conf\C-M" <br>　　# Ctrl-Alt-h 打开vi编辑器编辑apache的配置文件 <br>　　<br>　　"^[^L":"stardict &amp; &amp;&gt;/dev/null &amp;&amp; disown\C-M" <br>　　# Ctrl-Alt-l -&gt;&gt; 运行星际译王(l-&gt;look up查询的意思） <br>　　<br>　　"^[^O":"soffice &amp; &amp;&gt;/dev/null &amp;&amp; disown\C-M" <br>　　# Ctrl-Alt-o -&gt;&gt; 打开Openoffice <br>　　<br>　　"^[^P":"opera &amp; &amp;&gt;/dev/null &amp;&amp; disown\C-M" <br>　　# Ctrl-Alt-p -&gt;&gt; 大名鼎鼎的浏览器Opera <br>　　<br>　　"^[^X":"xmms &amp; &amp;&gt;/dev/null &amp;&amp; disown\C-M" <br>　　<br>　　<a  href="http://softtest.chinaitlab.com/" class="channel_keylink" target="_blank">测试</a>一下： <br>　　su - <br>　　&lt;Press Ctrl-Alt-X&gt; </p><img src ="http://www.cppblog.com/mydriverc/aggbug/98204.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-09 22:48 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/09/98204.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>新手看招 Linux系统下设置用户登录环境</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/09/98203.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Fri, 09 Oct 2009 14:39:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/09/98203.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98203.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/09/98203.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98203.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98203.html</trackback:ping><description><![CDATA[<span class="a14c">
<p style="text-indent: 2em;">用户在使用Linux系统的时候，还需要相关的工作环境。为此，管理员应为用户设置登录环境。 </p>
<p style="text-indent: 2em;"> </p>
<p style="text-indent: 2em;">当用户登录Linux系统后，通常接触的第一个软件环境就是bash命令解释程序，这是除了系统核心之外最重要的软件环境。在Linux系统中，软件环境的配置信息通常都存放在一些配置文件中。 </p>
<p style="text-indent: 2em;"> </p>
<p style="text-indent: 2em;">以下是一些较为重要的Shell环境配置文件： </p>
<p style="text-indent: 2em;"> </p>
<p style="text-indent: 2em;">◆/etc/bashrc 包含系统定义的命令别名和bash的环境变量定义。 </p>
<p style="text-indent: 2em;"> </p>
<p style="text-indent: 2em;">◆/etc/profile 包含系统的环境定义，并指定启动时必须运行的程序。 </p>
<p style="text-indent: 2em;"> </p>
<p style="text-indent: 2em;">◆/etc/inputrc 包含系统的键盘设定，以及针对不同终端程序的键位配置信息。 </p>
<p style="text-indent: 2em;"> </p>
<p style="text-indent: 2em;">◆$HOME/.bashrc 包含为用户定义的命令别名和bash的环境变量定义。 </p>
<p style="text-indent: 2em;"> </p>
<p style="text-indent: 2em;">◆$HOME/bash_profile 包含为用户定义的环境变量，并指定用户登录时需要启动的程序。 </p>
<p style="text-indent: 2em;"> </p>
<p style="text-indent: 2em;">◆$HOME/.inputrc 包含用户的键盘设定，以及针对用户终端的键位配置信息。 </p>
<p style="text-indent: 2em;"> </p>
<p style="text-indent: 2em;">这些文件都是采用Shell语言编写的系统脚本文件，通常用户目录下的配置文件与/etc目录中相对应的文件大致相同。 </p>
</span><img src ="http://www.cppblog.com/mydriverc/aggbug/98203.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-09 22:39 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/09/98203.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux中忘记了root密码的解决方法</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/09/98200.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Fri, 09 Oct 2009 14:29:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/09/98200.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98200.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/09/98200.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98200.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98200.html</trackback:ping><description><![CDATA[忘记了root密码只需以单用户方式进入系统，修改root的密码然后再重新启动即可。过程如下所示。 <br>　　<strong><wbr>进入单用户模式</strong>
<div class="ns_content"><wbr> <br>　　系统自检后，进入 GRUB 的引导菜单 <br>&nbsp;&nbsp;&nbsp;&nbsp; 利用方向键选择"Red Flag Desktop "这一项，然后按键盘上的"E"键，进入编辑模式。 <br>&nbsp;&nbsp;&nbsp;&nbsp; 利用方向键选择"kernel /boot/vmlinux-2.6.9-5.34DT ro root=LABEL=/ vga=785 ..."这一项，然后按键盘上的"E"键， <br>&nbsp;&nbsp;&nbsp;&nbsp; 利用方向键将光标移至"/vmlinuz-2.6.9-5.34DT"后，"ro root="之前，输入"空格single"，按回车键后返回编辑模式，再按键盘上的"B"键，过几秒钟后就会进入单用户模式， <br>&nbsp;&nbsp;&nbsp;&nbsp;<strong><wbr>开始修改密码 <br></strong><wbr>　　<strong><wbr>方法1：</strong><wbr> <br>　　在"sh-3.00#"后输入： <br><font style="line-height: 1.3em;" color="#ff0000">passwd root</font><wbr> <br>，回车； <br>　　在"New password:"后输入您的新密码，回车； <br>　　在"Retype new password:"后输入确认密码，回车，提示密码修改成功； <br>　　返回到"sh-3.00#"后输入： <br><font style="line-height: 1.3em;" color="#ff0000">reboot</font><wbr> <br>，回车，重启后即可用新密码进行登录。 <br>　　<strong><wbr>方法2：修改/etc/shadow文件</strong><wbr> <br>　　由于红旗Linux5.0桌面版中/etc/shadow文件默认为只读，所以先修改其权限为读写。 <br>　　在"sh-3.00#"后输入： <br><font style="line-height: 1.3em;" color="#ff0000">chmod 600 /etc/shadow</font><wbr> <br>或 <br><font style="line-height: 1.3em;" color="#ff0000">chomd u+w /etc/shadow</font><wbr> <br>，回车即可更改其权限为读写； <br>　　<strong><wbr>使用VI编辑/etc/shadow文件</strong><wbr> <br>　　在"sh-3.00#"后输入： <br><font style="line-height: 1.3em;" color="#ff0000">vi /etc/shadow</font><wbr> <br>；打开shadow文件后，将第一行，即以root开头的一行中root:后和下一个:前的内容删除，不要删除冒号；类似于 <br>　　root::...... <br>　　删好后按" <br><font style="line-height: 1.3em;" color="#ff0000">:wq</font><wbr> <br>"或" <br><font style="line-height: 1.3em;" color="#ff0000">ZZ</font><wbr> <br>"即可保存文件返回到"sh-3.00#"提示符；再使用命令 <br><font style="line-height: 1.3em;" color="#ff0000">chmod 400 /etc/shadow</font><wbr> <br>或 <br><font style="line-height: 1.3em;" color="#ff0000">chomd u-w /etc/shadow</font><wbr> <br>，将权限设为默认的只读权限。 <br>　　最后在"sh-3.00#"后输入： <br><font style="line-height: 1.3em;" color="#ff0000">reboot</font><wbr> <br>，回车，重启后即可用空密码进行登录，登录后修改密码即可。</div><img src ="http://www.cppblog.com/mydriverc/aggbug/98200.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-09 22:29 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/09/98200.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>手动修改/etc/shadow中的用户密码</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/09/98196.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Fri, 09 Oct 2009 14:18:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/09/98196.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98196.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/09/98196.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98196.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98196.html</trackback:ping><description><![CDATA[/etc/shadow中格式如下<br>
#testaccount:<font color="#ff0000"><strong>$1$acQMceF9</strong></font><strong>$<font color="#0080ff">1SaCpG2qiKKA3eGolU4Fp0</font></strong>:13402:0:99999:7:::<br>
彩色段为加密后的密码，<font color="#ff0000">$1$表示采用的是md5加密</font>，<font color="#006666">绿色段是简单的字符串，</font><font color="#0080ff">蓝色段为加密后的密码</font><br>
<br>
<font color="#0080ff">以下命令可得到加密后的字符串，zz</font>为密码<br>
perl -e &#8217;print crypt("<font color="#ff0000">zz</font>","＼$1＼$<font color="#006666">acQMceF9</font>＼$"),"＼n"&#8217;<br>
<br>
结果如下<br>
$1$acQMceF9$1SaCpG2qiKKA3eGolU4Fp0<br>
<br>
用此段密码替换/etc/shadow中的密码部分即可<br><img src ="http://www.cppblog.com/mydriverc/aggbug/98196.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-09 22:18 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/09/98196.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux操作系统的口令安全问题详细解析（LINUX 启用shadow文件 口令保护）</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/09/98195.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Fri, 09 Oct 2009 14:16:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/09/98195.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98195.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/09/98195.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98195.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98195.html</trackback:ping><description><![CDATA[　　几乎所有的类Unix<a  href="http://detail.zol.com.cn/os_index/subcate121_list_1.html" class="hui14_line"><font style="color: #333333;">操作系统</font></a>的口令文件的格式都雷同，Linux亦不例外。口令安全是Linux操作系统的传统安全问题之一。 <br>
<br>
<strong>传统口令与影子口令 <br>
</strong><br>
/etc/passwd是存放用户的基本信息的口令文件。该口令文件的每一行都包含由6个冒号分隔的7个域： <br>
<br>
username: passwd: uid: gid: comments: Directory: shell <br>
<br>
以上从左到右7个域分别叙述如下： <br>
<br>
username：是用户登陆使用的名字。 <br>
<br>
passwd：是口令密文域。密文是加密过的口令。如果口令经过shadow则口令密文域只显示一个x，通常，口令都应该经过shadow以确保安全。如果口令密文域显示为*，则表明该用户名有效但不能登陆。如果口令密文域为空则表明该用户登陆不需要口令。 <br>
<br>
uid：系统用于唯一标识用户名的数字，uid系统是这样分配的： <br>
<br>
0 超级用户 <br>
<br>
1～10 守护程序和伪用户 <br>
<br>
11～99 系统保留用户 <br>
<br>
100～ 正常用户 <br>
<br>
gid：表示用户所在默认组号。由/etc/group文件决定。 <br>
<br>
comments：描述用户的个人信息。 <br>
<br>
directory：定义用户的初始工作目录。 <br>
<br>
shell：就是指定用户登陆到系统后启动的外壳程序。 <br>
<br>
表1列出了系统在安装过程中创建的标准用户，表中的内容和/etc/passwd文件的描述是一致的。 <br>
<br>
表2列出系统安装过程中创建的标准用户组，和/etc/group文件是一致的： <br>
<br>
Linux使用不可逆的加密算法如DES来加密口令，由于加密算法是不可逆的，所以从密文是得不到明文的。但问题在于，/etc/passwd文件是
全局可读的，加密的算法是公开的，如果有恶意用户取得了/etc/passwd文件，他就可以穷举所有可能的明文通过相同的算法计算出密文进行比较，直到
相同，于是他就破解了口令。因此，针对这种安全问题，Linux/Unix广泛采用了&#8220;shadow（影子）&#8221;机制，将加密的口令转移到/etc
/shadow文件里，该文件只为root超级用户可读，而同时/etc/passwd文件的密文域显示为一个x，从而最大限度减少密文泄露的机会。 <br>
<br>
/etc/shadow文件的每行是8个冒号分割的9个域，格式如下： <br>
<br>
username: passwd: lastchg: min: max: warn: inactive: expire: flag <br>
<br>
其中： <br>
<br>
lastchg：表示从1970年1月1日起到上次修改口令所经过的天数。 <br>
<br>
min：表示两次修改口令之间至少经过的天数。 <br>
<br>
max：表示口令还会有效的最大天数，如果是99999则表示永不过期。 <br>
<br>
warn：表示口令失效前多少天内系统向用户发出警告。 <br>
<br>
inactive：表示禁止登陆前用户名还有效的天数。 <br>
<br>
expire：表示用户被禁止登陆的时间。0 <br>
<br>
flag：无意义，未使用。 <br>
<br>
<br>
<strong>　启用影子口令 <br>
</strong><br>
RedHat Linux缺省安装shadow，如果你发现你的系统的/etc/passwd文件仍然可以看到密文，就说明你没有启用shadow。可以执行pwconv来启用shadow。 <br>
<br>
在RedHat Linux 7.1中，影子工具包（shadow utils）包含了几个工具支持以下功能： <br>
<br>
传统口令与影子口令之间的转换工具：pwconv、pwunconv。 <br>
<br>
验证口令，组和相应的影子文件：pwck、grpck。 <br>
<br>
以符合工业标准的方法增加、删除和修改用户帐户：useradd、usermod、userdel。 <br>
<br>
以符合工业标准的方法增加、删除和修改用户组：groupadd、groupmod、groupdel。 <br>
<br>
以符合工业标准的方法管理文件/etc/group。 <br>
<br>
无论系统是否启用shadow机制，上述工具都可以正常使用。 <br>
<br>
<strong>　更改Linux口令的最短长度 <br>
</strong><br>
Linux系统默认最短口令长度为5个字符，这个长度不足以保证口令的健壮性，应该改为最短8个字符，编辑/etc/login.defs文件，在此文件中，将 <br>
<br>
PASS_MIN_LEN　　5 <br>
<br>
改为： <br>
<br>
PASS_MIN_LEN　　8 <img src ="http://www.cppblog.com/mydriverc/aggbug/98195.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-09 22:16 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/09/98195.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux /etc/passwd,/etc/shadow　用户文件的说明</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/09/98193.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Fri, 09 Oct 2009 13:52:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/09/98193.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98193.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/09/98193.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98193.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98193.html</trackback:ping><description><![CDATA[linux操作系统的用户文件的说明
<br><strong>/<span class="hilite1">etc/passwd</span></strong>
<br>&nbsp; 该目录存储的是操作系统用户信息，该文件为所有用户可见。
<br>给linux系统添加一个帐号：
<br>&nbsp; useradd -g mysql -d /home/test -m test（：新建一个用户test, 属于mysql组，开始目录是/home/test）
<br>&nbsp; 然后进入 /<span class="hilite1">etc/passwd</span>，可以看到如下信息，在最后一行可以看到刚加的用户的信息。如下
<br>&nbsp;&nbsp; sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
<br>&nbsp;&nbsp; dovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologin
<br>&nbsp;&nbsp; webalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologin
<br>&nbsp;&nbsp; squid:x:23:23::/var/spool/squid:/sbin/nologin
<br>&nbsp;&nbsp; pcap:x:77:77::/var/arpwatch:/sbin/nologin
<br>&nbsp;&nbsp; haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
<br>&nbsp;&nbsp; xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
<br>&nbsp;&nbsp; hsqldb:x:96:96::/var/lib/hsqldb:/sbin/nologin
<br>&nbsp;&nbsp; gdm:x:42:42::/var/gdm:/sbin/nologin
<br>&nbsp;&nbsp; hzmc:x:500:500:hzmc:/home/hzmc:/bin/bash
<br>&nbsp;&nbsp; mysql:x:501:501::/home/mysql:/bin/bash
<br>&nbsp;&nbsp; chenhua:x:503:501::/home/chenhua:/bin/bash
<br>&nbsp;&nbsp; test:x:504:501::/home/test:/bin/bash
<br>可以看出/<span class="hilite1">etc/passwd</span>文件存放的是用户的信息，由6个分号组成的7个信息，解释如下
<br>&nbsp;&nbsp; （1）：用户名。
<br>&nbsp;&nbsp; （2）：密码（已经加密）
<br>&nbsp;&nbsp; （3）：UID（用户标识）,操作系统自己用的
<br>&nbsp;&nbsp; （4）：GID组标识。
<br>&nbsp;&nbsp; （5）：用户全名或本地帐号
<br>&nbsp;&nbsp; （6）：开始目录
<br>&nbsp;&nbsp; （7）：登录使用的Shell，就是对登录命令进行解析的工具。
<br>&nbsp; 下面为test用户设置密码，执行如下命令
<br>&nbsp;&nbsp; passwd test
<br>&nbsp;&nbsp; [root@localhost etc]# passwd test
<br>&nbsp;&nbsp;&nbsp;&nbsp; Changing password for user test.
<br>&nbsp;&nbsp;&nbsp;&nbsp; New UNIX password:
<br>&nbsp;&nbsp;&nbsp;&nbsp; Retype new UNIX password:
<br>&nbsp;&nbsp;&nbsp;&nbsp; passwd: all authentication tokens updated successfully.
<br>&nbsp;&nbsp; [root@localhost etc]#
<br>&nbsp; 然后进入/etc/shadow文件下面可以看到如下信息
<br>&nbsp; gdm:!!:14302:0:99999:7:::
<br>&nbsp; hzmc:$1$JZMjXqxJ$bvRpGQxbuRiEa86KPLhhC1:14302:0:99999:7:::
<br>&nbsp; mysql:!!:14315:0:99999:7:::
<br>&nbsp; chenhua:$1$YBJZNyXJ$BnpKFD58vSgqzsyRO0ZeO1:14316:0:99999:7:::
<br>&nbsp; test:$1$hKjqUA40$OelB9h3UKOgnttKgmRpFr/:14316:0:99999:7:::
<br>&nbsp; 可以发现，共有9个栏目
<br> （1）：帐号名称
<br> （2）：密码：这里是加密过的，但高手也可以解密的。要主要安全问题（代！符号标识该帐号不能用来登录）
<br> （3）：上次修改密码的日期
<br> （4）：密码不可被变更的天数
<br> （5）：密码需要被重新变更的天数（99999表示不需要变更）
<br> （6）：密码变更前提前几天警告
<br> （7）：帐号失效日期
<br> （8）：帐号取消日期
<br> （9）：保留条目，目前没用
<br><img src ="http://www.cppblog.com/mydriverc/aggbug/98193.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-09 21:52 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/09/98193.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>第一个visudo命令</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/08/98061.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Wed, 07 Oct 2009 16:42:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/08/98061.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98061.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/08/98061.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98061.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98061.html</trackback:ping><description><![CDATA[在root下运行visudo<br>添加<br>usr1 ALL=/usr/bin/reboot,/usr/bin/shutdown<br><br>到新用户下执行sudo reboot<br>执行成功。<br><br><br><img src ="http://www.cppblog.com/mydriverc/aggbug/98061.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-08 00:42 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/08/98061.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>visudo编辑sudoers配置文件(转)</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/08/98059.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Wed, 07 Oct 2009 16:31:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/08/98059.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98059.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/08/98059.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98059.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98059.html</trackback:ping><description><![CDATA[<div id="art" style="margin: 15px;">
<span id="ctl00_MainContentPlaceholder_ctl01_ctl00_lblEntry">
<div id="msgcns!E154F49F7F84310C!201" class="bvMsg">
<div>visudo编辑sudoers配置文件，不过也可以直接通过修改sudoers文件实现，不过编辑之前最好看一下它的sample.sudoers文件，里面有一个相当详细的例子可以参考。&nbsp;&nbsp;&nbsp;&nbsp; </div>
<div>空格部分用tab键代替<br>&nbsp; ＃第一部分：用户定义，将用户分为FULLTIMERS、PARTTIMERS和WEBMASTERS三类。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; User_Alias&nbsp;&nbsp; FULLTIMERS&nbsp;&nbsp; =&nbsp;&nbsp; millert,&nbsp;&nbsp; mikef,&nbsp;&nbsp; dowdy&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; User_Alias&nbsp;&nbsp; PARTTIMERS&nbsp;&nbsp; =&nbsp;&nbsp; bostley,&nbsp;&nbsp; jwfox,&nbsp;&nbsp; crawl&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; User_Alias&nbsp;&nbsp; WEBMASTERS&nbsp;&nbsp; =&nbsp;&nbsp; will,&nbsp;&nbsp; wendy,&nbsp;&nbsp; wim&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃第二部分，将操作类型分类。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Runas_Alias&nbsp;&nbsp; OP&nbsp;&nbsp; =&nbsp;&nbsp; root,&nbsp;&nbsp; operator&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Runas_Alias&nbsp;&nbsp; DB&nbsp;&nbsp; =&nbsp;&nbsp; oracle,&nbsp;&nbsp; sybase&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; #第三部分，将主机分类。这些都是随便分得，目的是为了更好地管理。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Host_Alias&nbsp;&nbsp; SPARC&nbsp;&nbsp; =&nbsp;&nbsp; bigtime,&nbsp;&nbsp; eclipse,&nbsp;&nbsp; moet,&nbsp;&nbsp; anchor&nbsp;&nbsp; :&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; SGI&nbsp;&nbsp; =&nbsp;&nbsp; grolsch,&nbsp;&nbsp; dandelion,&nbsp;&nbsp; black&nbsp;&nbsp; :&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ALPHA&nbsp;&nbsp; =&nbsp;&nbsp; widget,&nbsp;&nbsp; thalamus,&nbsp;&nbsp; foobar&nbsp;&nbsp; :&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; HPPA&nbsp;&nbsp; =&nbsp;&nbsp; boa,&nbsp;&nbsp; nag,&nbsp;&nbsp; python&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Host_Alias&nbsp;&nbsp; CUNETS&nbsp;&nbsp; =&nbsp;&nbsp; 128.138.0.0/255.255.0.0&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Host_Alias&nbsp;&nbsp; CSNETS&nbsp;&nbsp; =&nbsp;&nbsp; 128.138.243.0,&nbsp;&nbsp; 128.138.204.0/24,&nbsp;&nbsp; 128.138.242.0&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Host_Alias&nbsp;&nbsp; SERVERS&nbsp;&nbsp; =&nbsp;&nbsp; master,&nbsp;&nbsp; mail,&nbsp;&nbsp; www,&nbsp;&nbsp; ns&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Host_Alias&nbsp;&nbsp; CDROM&nbsp;&nbsp; =&nbsp;&nbsp; orion,&nbsp;&nbsp; perseus,&nbsp;&nbsp; hercules&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃第四部分，定义命令和命令地路径。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; DUMPS&nbsp;&nbsp; =&nbsp;&nbsp; /usr/bin/mt,&nbsp;&nbsp; /usr/sbin/dump,&nbsp;&nbsp; /usr/sbin/rdump,&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; /usr/sbin/restore,&nbsp;&nbsp; /usr/sbin/rrestore&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; KILL&nbsp;&nbsp; =&nbsp;&nbsp; /usr/bin/kill&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; PRINTING&nbsp;&nbsp; =&nbsp;&nbsp; /usr/sbin/lpc,&nbsp;&nbsp; /usr/bin/lprm&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; SHUTDOWN&nbsp;&nbsp; =&nbsp;&nbsp; /usr/sbin/shutdown&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; HALT&nbsp;&nbsp; =&nbsp;&nbsp; /usr/sbin/halt,&nbsp;&nbsp; /usr/sbin/fasthalt&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; REBOOT&nbsp;&nbsp; =&nbsp;&nbsp; /usr/sbin/reboot,&nbsp;&nbsp; /usr/sbin/fastboot&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; SHELLS&nbsp;&nbsp; =&nbsp;&nbsp; /usr/bin/sh,&nbsp;&nbsp; /usr/bin/csh,&nbsp;&nbsp; /usr/bin/ksh,&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; /usr/local/bin/tcsh,&nbsp;&nbsp; /usr/bin/rsh,&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; /usr/local/bin/zsh&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; SU&nbsp;&nbsp; =&nbsp;&nbsp; /usr/bin/su&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;＃
这里是针对不同的用户采用不同地策略，比如默认所有的syslog直接通过auth&nbsp;&nbsp;
输出。FULLTIMERS组不用看到lecture（第一次运行时产生的消息）；用户millert使用sudo时不用输入密码；以及logfile的
路径在/var/log/sudo.log而且每一行日志中必须包括年。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Defaults&nbsp;&nbsp; syslog=auth&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Defaults:FULLTIMERS&nbsp;&nbsp; !lecture&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Defaults:millert&nbsp;&nbsp; !authenticate&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; <a  href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#68;&#101;&#102;&#97;&#117;&#108;&#116;&#115;&#64;&#83;&#69;&#82;&#86;&#69;&#82;&#83;">Defaults@SERVERS</a>&nbsp;&nbsp; log_year,&nbsp;&nbsp; logfile=/var/log/sudo.log&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃root和wheel组的成员拥有任何权利。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; root&nbsp;&nbsp; ALL&nbsp;&nbsp; =&nbsp;&nbsp; (ALL)&nbsp;&nbsp; ALL&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; %wheel&nbsp;&nbsp; ALL&nbsp;&nbsp; =&nbsp;&nbsp; (ALL)&nbsp;&nbsp; ALL&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;＃FULLTIMERS可以运行任何命令在任何主机而不用输入自己的密码&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; FULLTIMERS&nbsp;&nbsp; ALL&nbsp;&nbsp; =&nbsp;&nbsp; NOPASSWD:&nbsp;&nbsp; ALL&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃PARTTIMERS可以运行任何命令在任何主机，但是必须先验证自己的密码。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; PARTTIMERS&nbsp;&nbsp; ALL&nbsp;&nbsp; =&nbsp;&nbsp; ALL&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃jack可以运行任何命令在定义地CSNET（128.138.243.0,&nbsp;&nbsp; 128.138.242.0和128.138.204.0/24的子网）中，不过注意前两个不需要匹配子网掩码，而后一个必须匹配掩码。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; jack&nbsp;&nbsp; CSNETS&nbsp;&nbsp; =&nbsp;&nbsp; ALL&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃lisa可以运行任何命令在定义为CUNETS（128.138.0.0）的子网中主机上。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; lisa&nbsp;&nbsp; CUNETS&nbsp;&nbsp; =&nbsp;&nbsp; ALL&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; #用户operator可以运行DUMPS,KILL,PRINTING,SHUTDOWN,HALT,REBOOT以及在/usr/oper/bin中的所有命令。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; operator&nbsp;&nbsp; ALL&nbsp;&nbsp; =&nbsp;&nbsp; DUMPS,&nbsp;&nbsp; KILL,&nbsp;&nbsp; PRINTING,&nbsp;&nbsp; SHUTDOWN,&nbsp;&nbsp; HALT,&nbsp;&nbsp; REBOOT,&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; /usr/oper/bin/&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃joe可以运行su&nbsp;&nbsp; operator命令&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; joe&nbsp;&nbsp; ALL&nbsp;&nbsp; =&nbsp;&nbsp; /usr/bin/su&nbsp;&nbsp; operator&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃pete可以为除root之外地用户修改密码。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; pete&nbsp;&nbsp; HPPA&nbsp;&nbsp; =&nbsp;&nbsp; /usr/bin/passwd&nbsp;&nbsp; [A-z]*,&nbsp;&nbsp; !/usr/bin/passwd&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃bob可以在SPARC和SGI机器上和OP用户组中的root和operator一样运行如何命令。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; bob&nbsp;&nbsp; SPARC&nbsp;&nbsp; =&nbsp;&nbsp; (OP)&nbsp;&nbsp; ALL&nbsp;&nbsp; :&nbsp;&nbsp; SGI&nbsp;&nbsp; =&nbsp;&nbsp; (OP)&nbsp;&nbsp; ALL&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;＃jim可以运行任何命令在biglab网络组中。Sudo默认&#8220;＋&#8221;是一个网络组地前缀。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; jim&nbsp;&nbsp; +biglab&nbsp;&nbsp; =&nbsp;&nbsp; ALL&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃在secretaries中地用户帮助管理打印机，并且可以运行adduser和rmuser命令。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; +secretaries&nbsp;&nbsp; ALL&nbsp;&nbsp; =&nbsp;&nbsp; PRINTING,&nbsp;&nbsp; /usr/bin/adduser,&nbsp;&nbsp; /usr/bin/rmuser&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃fred能够直接运行oracle或者sybase数据库。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; fred&nbsp;&nbsp; ALL&nbsp;&nbsp; =&nbsp;&nbsp; (DB)&nbsp;&nbsp; NOPASSWD:&nbsp;&nbsp; ALL&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃john可以在ALPHA机器上，su除了root之外地所有人。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; john&nbsp;&nbsp; ALPHA&nbsp;&nbsp; =&nbsp;&nbsp; /usr/bin/su&nbsp;&nbsp; [!-]*,&nbsp;&nbsp; !/usr/bin/su&nbsp;&nbsp; *root*&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃jen可以在除了SERVERS主机组的机器上运行任何命令。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; jen&nbsp;&nbsp; ALL,&nbsp;&nbsp; !SERVERS&nbsp;&nbsp; =&nbsp;&nbsp; ALL&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃jill可以在SERVERS上运行/usr/bin/中的除了su和shell命令之外的所有命令。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; jill&nbsp;&nbsp; SERVERS&nbsp;&nbsp; =&nbsp;&nbsp; /usr/bin/,&nbsp;&nbsp; !SU,&nbsp;&nbsp; !SHELLS&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃steve可以作为普通用户运行在CSNETS主机上的/usr/local/op_commands/内的任何命令。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; steve&nbsp;&nbsp; CSNETS&nbsp;&nbsp; =&nbsp;&nbsp; (operator)&nbsp;&nbsp; /usr/local/op_commands/&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;＃matt可以在他的个人工作站上运行kill命令。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; matt&nbsp;&nbsp; valkyrie&nbsp;&nbsp; =&nbsp;&nbsp; KILL&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃WEBMASTERS用户组中的用户可以以www的用户名运行任何命令或者可以su&nbsp;&nbsp; www。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; WEBMASTERS&nbsp;&nbsp; www&nbsp;&nbsp; =&nbsp;&nbsp; (www)&nbsp;&nbsp; ALL,&nbsp;&nbsp; (root)&nbsp;&nbsp; /usr/bin/su&nbsp;&nbsp; www&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ＃任何用户可以mount或者umount一个cd-rom在CDROM主机上，而不用输入密码。&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ALL&nbsp;&nbsp; CDROM&nbsp;&nbsp; =&nbsp;&nbsp; NOPASSWD:&nbsp;&nbsp; /sbin/umount&nbsp;&nbsp; /CDROM,&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; /sbin/mount&nbsp;&nbsp; -o&nbsp;&nbsp; nosuid,nodev&nbsp;&nbsp; /dev/cd0a&nbsp;&nbsp; /CDROM&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp; 10)&nbsp;&nbsp; 我的sudoers&nbsp;&nbsp; 配置文件是这样的&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; User_Alias&nbsp;&nbsp; ADMIN&nbsp;&nbsp; =&nbsp;&nbsp; root,username&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Runas_Alias&nbsp;&nbsp; OP&nbsp;&nbsp; =&nbsp;&nbsp; username&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; IPCHAINS&nbsp;&nbsp; =&nbsp;&nbsp; /usr/bin/ipchains&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; EDIT&nbsp;&nbsp; =&nbsp;&nbsp; /bin/vi&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; SHUTDOWN&nbsp;&nbsp; =/sbin/shutdown&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; HALT&nbsp;&nbsp; =&nbsp;&nbsp; /usr/bin/halt&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; DEL&nbsp;&nbsp; =&nbsp;&nbsp; /bin/rm&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; COPY=&nbsp;&nbsp; /bin/cp&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; SU=/bin/su&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; SLEEP=&nbsp;&nbsp; /bin/sleep&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; REBOOT&nbsp;&nbsp; =&nbsp;&nbsp; /usr/bin/reboot&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; CHMOD=/bin/chmod&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; HWCLOCK=/sbin/hwclock&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; TRACET=/usr/sbin/traceroute&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; VIPW&nbsp;&nbsp; =&nbsp;&nbsp; /sbin/route&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; PASSWD=/usr/bin/passwd&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; IPSEC=/usr/local/sbin/ipsec&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; ARP=/sbin/arp&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; Cmnd_Alias&nbsp;&nbsp; HOSTNAME=/bin/hostname&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; root&nbsp;&nbsp; ALL&nbsp;&nbsp; =&nbsp;&nbsp; (ALL)&nbsp;&nbsp; ALL&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:HOSTNAME&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:ARP&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:HWCLOCK&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:IPCHAINS&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:HALT&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:SHUTDOWN&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:REBOOT&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:CHMOD&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:IPSEC&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:PASSWD&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:TRACET&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:DEL&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:COPY&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:SU&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:EDIT&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:SLEEP&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ADMIN&nbsp;&nbsp; SERVERNAME=(ALL)&nbsp;&nbsp; NOPASSWD:ROUTE&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp; sudo的使用相对地简单，只要将sudo和sudoers命令拷贝到相应的路径即可。Sudo命令可以rename成你所喜欢的名字，sudoers也一样。 </div>
</div>
</span>
</div><img src ="http://www.cppblog.com/mydriverc/aggbug/98059.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-08 00:31 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/08/98059.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>重新启动后的裸设备的属主和权限</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/07/98056.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Wed, 07 Oct 2009 15:50:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/07/98056.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98056.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/07/98056.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98056.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98056.html</trackback:ping><description><![CDATA[使用chown和chmod，执行reboot后，<br>使用ls -l /dev/raw/raw1的属主没有变回root。<br><br><img src ="http://www.cppblog.com/mydriverc/aggbug/98056.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-07 23:50 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/07/98056.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux用户和用户组管理（转）</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/07/98054.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Wed, 07 Oct 2009 15:39:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/07/98054.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98054.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/07/98054.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98054.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98054.html</trackback:ping><description><![CDATA[Linux系统是一个多用户多任务的分时操作系统，任何一个要使用系统资源的用户，都必须首先向系统管理员申请一个账号，然后以这个账号的身份进入
系统。用户的账号一方面可以帮助系统管理员对使用系统的用户进行跟踪，并控制他们对系统资源的访问；另一方面也可以帮助用户组织文件，并为用户提供安全性
保护。每个用户账号都拥有一个惟一的用户名和各自的口令。用户在登录时键入正确的用户名和口令后，就能够进入系统和自己的主目录。
<p>　　实现用户账号的管理，要完成的工作主要有如下几个方面： <br>
&#183; 用户账号的添加、删除与修改。 <br>
&#183; 用户口令的管理。 <br>
&#183; 用户组的管理。 </p>
<p><br>
一、Linux系统用户账号的管理</p>
<p>　　用户账号的管理工作主要涉及到用户账号的添加、修改和删除。</p>
<p>　　添加用户账号就是在系统中创建一个新账号，然后为新账号分配用户号、用户组、主目录和登录Shell等资源。刚添加的账号是被锁定的，无法使用。 </p>
<p>1、添加新的用户账号使用useradd命令，其语法如下：</p>
<p>　　<br>
useradd 选项 用户名</p>
<p><br>
其中各选项含义如下：</p>
<p>　　-c comment 指定一段注释性描述。</p>
<p>　　-d 目录 指定用户主目录，如果此目录不存在，则同时使用-m选项，可以创建主目录。</p>
<p>　　-g 用户组 指定用户所属的用户组。</p>
<p>　　-G 用户组，用户组 指定用户所属的附加组。</p>
<p>　　-s Shell文件 指定用户的登录Shell。</p>
<p>　　-u 用户号 指定用户的用户号，如果同时有-o选项，则可以重复使用其他用户的标识号。</p>
<p>　　用户名 指定新账号的登录名。</p>
<p><br>
2、例子说明</p>
<p>　　例1：</p>
<p>　　<br>
# useradd &#8211;d /usr/sam -m sam</p>
<p><br>
此命令创建了一个用户sam， <br>
其中-d和-m选项用来为登录名sam产生一个主目录/usr/sam（/usr为默认的用户主目录所在的父目录）。</p>
<p><br>
例2：</p>
<p>　　<br>
# useradd -s /bin/sh -g group &#8211;G adm,root gem</p>
<p><br>
此命令新建了一个用户gem，该用户的登录Shell是/bin/sh，它属于group用户组，同时又属于adm和root用户组，其中group用户组是其主组。 <br>
这里可能新建组：#groupadd group及groupadd adm　 <br>
<br>
增加用户账号就是在/etc/passwd文件中为新用户增加一条记录，同时更新其他系统文件如/etc/shadow, /etc/group等。</p>
<p>　　Linux提供了集成的系统管理工具userconf，它可以用来对用户账号进行统一管理。</p>
<p><br>
3、删除帐号</p>
<p>　　如果一个用户的账号不再使用，可以从系统中删除。删除用户账号就是要将/etc/passwd等系统文件中的该用户记录删除，必要时还删除用户的主目录。删除一个已有的用户账号使用userdel命令，其格式如下：</p>
<p>　　<br>
userdel 选项 用户名</p>
<p><br>
常用的选项是-r，它的作用是把用户的主目录一起删除。</p>
<p>　　例如：</p>
<p>　　<br>
# userdel sam</p>
<p><br>
此命令删除用户sam在系统文件中（主要是/etc/passwd, /etc/shadow, /etc/group等）的记录，同时删除用户的主目录。</p>
<p><br>
4、修改帐号</p>
<p>　　修改用户账号就是根据实际情况更改用户的有关属性，如用户号、主目录、用户组、登录Shell等。</p>
<p>　　修改已有用户的信息使用usermod命令，其格式如下：</p>
<p>　　<br>
usermod 选项 用户名</p>
<p><br>
常用的选项包括-c, -d, -m, -g, -G, -s, -u以及-o等，这些选项的意义与useradd命令中的选项一样，可以为用户指定新的资源值。另外，有些系统可以使用如下选项：</p>
<p>　　<br>
-l 新用户名</p>
<p><br>
这个选项指定一个新的账号，即将原来的用户名改为新的用户名。</p>
<p>　　例如：</p>
<p>　　<br>
# usermod -s /bin/ksh -d /home/z &#8211;g developer sam</p>
<p><br>
此命令将用户sam的登录Shell修改为ksh，主目录改为/home/z，用户组改为developer。</p>
<p><br>
5、用户口令的管理</p>
<p>　　用户管理的一项重要内容是用户口令的管理。用户账号刚创建时没有口令，但是被系统锁定，无法使用，必须为其指定口令后才可以使用，即使是指定空口令。</p>
<p>　　指定和修改用户口令的Shell命令是passwd。超级用户可以为自己和其他用户指定口令，普通用户只能用它修改自己的口令。命令的格式为：</p>
<p>　　<br>
passwd 选项 用户名</p>
<p><br>
可使用的选项：</p>
<p>　　-l 锁定口令，即禁用账号。</p>
<p>　　-u 口令解锁。</p>
<p>　　-d 使账号无口令。</p>
<p>　　-f 强迫用户下次登录时修改口令。</p>
<p>　　如果默认用户名，则修改当前用户的口令。</p>
<p><br>
例如，假设当前用户是sam，则下面的命令修改该用户自己的口令：</p>
<p>　　$ passwd</p>
<p>　　Old password:******</p>
<p>　　New password:*******</p>
<p>　　Re-enter new password:*******</p>
<p><br>
如果是超级用户，可以用下列形式指定任何用户的口令：</p>
<p>　　# passwd sam</p>
<p>　　New password:*******</p>
<p>　　Re-enter new password:*******</p>
<p><br>
普通用户修改自己的口令时，passwd命令会先询问原口令，验证后再要求用户输入两遍新口令，如果两次输入的口令一致，则将这个口令指定给用户；而超级用户为用户指定口令时，就不需要知道原口令。 </p>
<p>　　为了系统安全起见，用户应该选择比较复杂的口令，例如最好使用8位长的口令，口令中包含有大写、小写字母和数字，并且应该与姓名、生日等不相同。</p>
<p>　　为用户指定空口令时，执行下列形式的命令：</p>
<p>　　<br>
# passwd -d sam</p>
<p><br>
此命令将用户sam的口令删除，这样用户sam下一次登录时，系统就不再询问口令。</p>
<p>　　passwd命令还可以用-l(lock)选项锁定某一用户，使其不能登录，例如：</p>
<p>　　<br>
# passwd -l sam</p>
<p> </p>
<p> wingger 回复于：2004-11-04 13:03:40</p>
<p>二、Linux系统用户组的管理</p>
<p>　　每个用户都有一个用户组，系统可以对一个用户组中的所有用户进行集中管理。不同Linux 系统对用户组的规定有所不同，如Linux下的用户属于与它同名的用户组，这个用户组在创建用户时同时创建。  <br>
用户组的管理涉及用户组的添加、删除和修改。组的增加、删除和修改实际上就是对/etc/group文件的更新。</p>
<p>1、增加一个新的用户组使用groupadd命令。其格式如下： <br>
<br>
groupadd 选项 用户组</p>
<p>　　可以使用的选项有： <br>
-g GID 指定新用户组的组标识号（GID）。</p>
<p>　　-o 一般与-g选项同时使用，表示新用户组的GID可以与系统已有用户组的GID相同。</p>
<p>　　例1： <br>
<br>
# groupadd group1</p>
<p>　　此命令向系统中增加了一个新组group1，新组的组标识号是在当前已有的最大组标识号的基础上加1。</p>
<p>　　例2： <br>
<br>
#groupadd -g 101 group2</p>
<p>　　此命令向系统中增加了一个新组group2，同时指定新组的组标识号是101。</p>
<p>2、如果要删除一个已有的用户组，使用groupdel命令，其格式如下： <br>
<br>
groupdel 用户组</p>
<p>　　例如： <br>
<br>
#groupdel group1</p>
<p>　　此命令从系统中删除组group1。</p>
<p>3、修改用户组的属性使用groupmod命令。其语法如下： <br>
<br>
groupmod 选项 用户组</p>
<p>　　常用的选项有： <br>
-g GID 为用户组指定新的组标识号。</p>
<p>　　-o 与-g选项同时使用，用户组的新GID可以与系统已有用户组的GID相同。</p>
<p>　　-n新用户组 将用户组的名字改为新名字</p>
<p><br>
例1： <br>
<br>
# groupmod -g 102 group2</p>
<p>　　此命令将组group2的组标识号修改为102。</p>
<p>　　例2： <br>
<br>
# groupmod &#8211;g 10000 -n group3 group2</p>
<p>　　此命令将组group2的标识号改为10000，组名修改为group3。</p>
<p>4、如果一个用户同时属于多个用户组，那么用户可以在用户组之间切换，以便具有其他用户组的权限。用户可以在登录后，使用命令newgrp切换到其他用户组，这个命令的参数就是目的用户组。例如： <br>
<br>
$ newgrp root</p>
<p>　　这条命令将当前用户切换到root用户组，前提条件是root用户组确实是该用户的主组或附加组。类似于用户账号的管理，用户组的管理也可以通过集成的系统管理工具来完成。</p>
<p> wingger 回复于：2004-11-04 13:21:16</p>
<p>三、与用户账号有关的系统文件</p>
<p>　　完成用户管理的工作有许多种方法，但是每一种方法实际上都是对有关的系统文件进行修改。与用户和用户组相关的信息都存放在一些系统文件中，这些文件包括/etc/passwd, /etc/shadow, /etc/group等。下面分别介绍这些文件的内容。 <br>
<br>
1、/etc/passwd文件是用户管理工作涉及的最重要的一个文件。Linux系统中的每个用户都在/etc/passwd文件中有一个对应的记录行，它记录了这个用户的一些基本属性。这个文件对所有用户都是可读的。它的内容类似下面的例子：</p>
<p>　　＃ cat /etc/passwd</p>
<p> </p>
<p>　　root:x:0:0:Superuser:/:</p>
<p>　　daemon:x:1:1:System daemons:/etc:</p>
<p>　　bin:x:2:2:Owner of system commands:/bin:</p>
<p>　　sys:x:3:3:Owner of system files:/usr/sys:</p>
<p>　　adm:x:4:4:System accounting:/usr/adm:</p>
<p>　　uucp:x:5:5:UUCP administrator:/usr/lib/uucp:</p>
<p>　　auth:x:7:21:Authentication administrator:/tcb/files/auth:</p>
<p>　　cron:x:9:16:Cron daemon:/usr/spool/cron:</p>
<p>　　listen:x:37:4:Network daemon:/usr/net/nls:</p>
<p>　　lp:x:71:18:Printer administrator:/usr/spool/lp:</p>
<p>　　sam:x:200:50:Sam san:/usr/sam:/bin/sh</p>
<p><br>
从上面的例子我们可以看到，/etc/passwd中一行记录对应着一个用户，每行记录又被冒号(:)分隔为7个字段，其格式和具体含义如下：</p>
<p>　　<br>
用户名:口令:用户标识号:组标识号:注释性描述:主目录:登录Shell</p>
<p><br>
1）&#8220;用户名&#8221;是代表用户账号的字符串。通常长度不超过8个字符，并且由大小写字母和/或数字组成。登录名中不能有冒号(:)，因为冒号在这里是分隔符。为了兼容起见，登录名中最好不要包含点字符(.)，并且不使用连字符(-)和加号(+)打头。</p>
<p>　　2）&#8220;口令&#8221;一些系统中，存放着加密后的用户口令字。。虽然这个字段存放的只是用户口令的加密串，不是明文，但是由于/etc/passwd文
件对所有用户都可读，所以这仍是一个安全隐患。因此，现在许多Linux
系统（如SVR4）都使用了shadow技术，把真正的加密后的用户口令字存放到/etc/shadow文件中，而在/etc/passwd文件的口令字
段中只存放一个特殊的字符，例如&#8220;x&#8221;或者&#8220;*&#8221;。</p>
<p>　　3）&#8220;用户标识号&#8221;是一个整数，系统内部用它来标识用户。一般情况下它与用户名是一一对应的。如果几个用户名对应的用户标识号是一样的，系统内部将把它们视为同一个用户，但是它们可以有不同的口令、不同的主目录以及不同的登录Shell等。</p>
<p>　　通常用户标识号的取值范围是0～65 535。0是超级用户root的标识号，1～99由系统保留，作为管理账号，普通用户的标识号从100开始。在Linux系统中，这个界限是500。</p>
<p>　　4）&#8220;组标识号&#8221;字段记录的是用户所属的用户组。它对应着/etc/group文件中的一条记录。</p>
<p>　　5)&#8220;注释性描述&#8221;字段记录着用户的一些个人情况，例如用户的真实姓名、电话、地址等，这个字段并没有什么实际的用途。在不同的Linux
系统中，这个字段的格式并没有统一。在许多Linux系统中，这个字段存放的是一段任意的注释性描述文字，用做finger命令的输出。</p>
<p>　　6)&#8220;主目录&#8221;，也就是用户的起始工作目录，它是用户在登录到系统之后所处的目录。在大多数系统中，各用户的主目录都被组织在同一个特定的目录
下，而用户主目录的名称就是该用户的登录名。各用户对自己的主目录有读、写、执行（搜索）权限，其他用户对此目录的访问权限则根据具体情况设置。</p>
<p>　　7)用户登录后，要启动一个进程，负责将用户的操作传给内核，这个进程是用户登录到系统后运行的命令解释器或某个特定的程序，即Shell。
Shell是用户与Linux系统之间的接口。Linux的Shell有许多种，每种都有不同的特点。常用的有sh(Bourne Shell),
csh(C Shell), ksh(Korn Shell), tcsh(TENEX/TOPS-20 type C Shell),
bash(Bourne Again
Shell)等。系统管理员可以根据系统情况和用户习惯为用户指定某个Shell。如果不指定Shell，那么系统使用sh为默认的登录Shell，即这
个字段的值为/bin/sh。</p>
<p>　　用户的登录Shell也可以指定为某个特定的程序（此程序不是一个命令解释器）。利用这一特点，我们可以限制用户只能运行指定的应用程序，在该应用程序运行结束后，用户就自动退出了系统。有些Linux 系统要求只有那些在系统中登记了的程序才能出现在这个字段中。</p>
<p><br>
8)系统中有一类用户称为伪用户（psuedo users），这些用户在/etc/passwd文件中也占有一条记录，但是不能登录，因为它们的登录Shell为空。它们的存在主要是方便系统管理，满足相应的系统进程对文件属主的要求。常见的伪用户如下所示。</p>
<p>伪  用  户&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  含&nbsp;&nbsp;&nbsp;&nbsp;  义</p>
<p> bin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  拥有可执行的用户命令文件</p>
<p> sys&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  拥有系统文件</p>
<p> adm&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  拥有帐户文件</p>
<p> uucp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  UUCP使用</p>
<p> lp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  lp或lpd子系统使用</p>
<p> nobody&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  NFS使用</p>
<p> 拥有帐户文件 <br>
<br>
除了上面列出的伪用户外，还有许多标准的伪用户，例如：audit, cron, mail, usenet等，它们也都各自为相关的进程和文件所需要。</p>
<p>　　由于/etc/passwd文件是所有用户都可读的，如果用户的密码太简单或规律比较明显的话，一台普通的计算机就能够很容易地将它破解，因此
对安全性要求较高的Linux系统都把加密后的口令字分离出来，单独存放在一个文件中，这个文件是/etc/shadow文件。只有超级用户才拥有该文件
读权限，这就保证了用户密码的安全性。</p>
<p><br>
2、/etc/shadow中的记录行与/etc/passwd中的一一对应，它由pwconv命令根据/etc/passwd中的数据自动产生。它的文件格式与/etc/passwd类似，由若干个字段组成，字段之间用&#8220;:&#8221;隔开。这些字段是：</p>
<p>　　<br>
登录名:加密口令:最后一次修改时间:最小时间间隔:最大时间间隔:警告时间:不活动时间:失效时间:标志</p>
<p><br>
1）&#8220;登录名&#8221;是与/etc/passwd文件中的登录名相一致的用户账号 <br>
2）&#8220;口令&#8221;字段存放的是加密后的用户口令字，长度为13个字符。如果为空，则对应用户没有口令，登录时不需要口令；如果含有不属于集合 { ./0-9A-Za-z }中的字符，则对应的用户不能登录。 <br>
3）&#8220;最后一次修改时间&#8221;表示的是从某个时刻起，到用户最后一次修改口令时的天数。时间起点对不同的系统可能不一样。例如在SCO Linux 中，这个时间起点是1970年1月1日。 <br>
4）&#8220;最小时间间隔&#8221;指的是两次修改口令之间所需的最小天数。 <br>
5）&#8220;最大时间间隔&#8221;指的是口令保持有效的最大天数。 <br>
6）&#8220;警告时间&#8221;字段表示的是从系统开始警告用户到用户密码正式失效之间的天数。 <br>
7）&#8220;不活动时间&#8221;表示的是用户没有登录活动但账号仍能保持有效的最大天数。 <br>
8）&#8220;失效时间&#8221;字段给出的是一个绝对的天数，如果使用了这个字段，那么就给出相应账号的生存期。期满后，该账号就不再是一个合法的账号，也就不能再用来登录了。</p>
<p>　　下面是/etc/shadow的一个例子：</p>
<p>　　<br>
＃ cat /etc/shadow</p>
<p> </p>
<p>　　root:Dnakfw28zf38w:8764:0:168:7:::</p>
<p>　　daemon:*::0:0::::</p>
<p>　　bin:*::0:0::::</p>
<p>　　sys:*::0:0::::</p>
<p>　　adm:*::0:0::::</p>
<p>　　uucp:*::0:0::::</p>
<p>　　nuucp:*::0:0::::</p>
<p>　　auth:*::0:0::::</p>
<p>　　cron:*::0:0::::</p>
<p>　　listen:*::0:0::::</p>
<p>　　lp:*::0:0::::</p>
<p>　　sam:EkdiSECLWPdSa:9740:0:0::::</p>
<p> </p>
<p>3、用户组的所有信息都存放在/etc/group文件中。</p>
<p>将用户分组是Linux
系统中对用户进行管理及控制访问权限的一种手段。每个用户都属于某个用户组；一个组中可以有多个用户，一个用户也可以属于不同的组。当一个用户同时是多个
组中的成员时，在/etc/passwd文件中记录的是用户所属的主组，也就是登录时所属的默认组，而其他组称为附加组。用户要访问属于附加组的文件时，
必须首先使用newgrp命令使自己成为所要访问的组中的成员。用户组的所有信息都存放在/etc/group文件中。此文件的格式也类似于/etc
/passwd文件，由冒号(:)隔开若干个字段，这些字段有：</p>
<p>　　<br>
组名:口令:组标识号:组内用户列表</p>
<p><br>
1）&#8220;组名&#8221;是用户组的名称，由字母或数字构成。与/etc/passwd中的登录名一样，组名不应重复。 <br>
2）&#8220;口令&#8221;字段存放的是用户组加密后的口令字。一般Linux 系统的用户组都没有口令，即这个字段一般为空，或者是*。 <br>
3）&#8220;组标识号&#8221;与用户标识号类似，也是一个整数，被系统内部用来标识组。 <br>
4）&#8220;组内用户列表&#8221;是属于这个组的所有用户的列表/b]，不同用户之间用逗号(,)分隔。这个用户组可能是用户的主组，也可能是附加组。</p>
<p>　　/etc/group文件的一个例子如下：</p>
<p>　　# cat /etc/group</p>
<p>　　root::0:root</p>
<p>　　bin::2:root,bin</p>
<p>　　sys::3:root,uucp</p>
<p>　　adm::4:root,adm</p>
<p>　　daemon::5:root,daemon</p>
<p>　　lp::7:root,lp</p>
<p>　　users::20:root,sam</p>
<p><br>
wingger 回复于：2004-11-04 13:31:28</p>
<p>四、添加量用户批</p>
<p>　　添加和删除用户对每位Linux系统管理员都是轻而易举的事，比较棘手的是如果要添加几十个、上百个甚至上千个用户时，我们不太可能还使用
useradd一个一个地添加，必然要找一种简便的创建大量用户的方法。Linux系统提供了创建大量用户的工具，可以让您立即创建大量用户，方法如下：
<br>
<br>
（1）先编辑一个文本用户文件，每一列按照/etc/passwd密码文件的格式书写，要注意每个用户的用户名、UID、宿主目录都不可以相同，其中密码栏可以留做空白或输入x号。一个范例文件user.txt内容如下：</p>
<p>　　user001::600:100:user:/home/user001:/bin/bash</p>
<p>　　user002::601:100:user:/home/user002:/bin/bash</p>
<p>　　user003::602:100:user:/home/user003:/bin/bash</p>
<p>　　user004::603:100:user:/home/user004:/bin/bash</p>
<p>　　user005::604:100:user:/home/user005:/bin/bash</p>
<p>　　user006::605:100:user:/home/user006:/bin/bash</p>
<p><br>
（2）以root身份执行命令/usr/sbin/newusers，从刚创建的用户文件user.txt中导入数据，创建用户：</p>
<p>　　<br>
# newusers &lt; user.txt</p>
<p><br>
然后可以执行命令vipw或vi /etc/passwd检查/etc/passwd文件是否已经出现这些用户的数据，并且用户的宿主目录是否已经创建。</p>
<p>　　（3）执行命令/usr/sbin/pwunconv，将/etc/shadow产生的shadow密码解码，然后回写到/etc
/passwd中，并将/etc/shadow的shadow密码栏删掉。这是为了方便下一步的密码转换工作，即先取消shadow
password功能。</p>
<p>　　<br>
# pwunconv</p>
<p><br>
（4）编辑每个用户的密码对照文件，范例文件passwd.txt内容如下：</p>
<p>　　user001:密码</p>
<p>　　user002:密码</p>
<p>　　user003:密码</p>
<p>　　user004:密码</p>
<p>　　user005:密码</p>
<p>　　user006:密码</p>
<p><br>
（5）以root身份执行命令/usr/sbin/chpasswd，创建用户密码，chpasswd会将经过/usr/bin/passwd命令编码过的密码写入/etc/passwd的密码栏。</p>
<p>　　<br>
# chpasswd &lt; passwd.txt</p>
<p><br>
（6）确定密码经编码写入/etc/passwd的密码栏后，执行命令/usr/sbin/pwconv将密码编码为shadow password，并将结果写入/etc/shadow。</p>
<p>　　<br>
# pwconv</p>
<p><br>
这样就完成了大量用户的创建了，之后您可以到/home下检查这些用户宿主目录的权限设置是否都正确，并登录验证用户密码是否正确。</p>
<p> wingger 回复于：2004-11-04 13:39:12</p>
<p>五、赋予普通用户特殊权限</p>
<p>　　在Linux系统中，管理员往往不止一人，若每位管理员都用root身份进行管理工作，根本无法弄清楚谁该做什么。所以最好的方式是：管理员创建一些普通用户，分配一部分系统管理工作给他们。 <br>
<br>
我们不可以使用su让他们直接变成root，因为这些用户都必须知道root的密码，这种方法很不安全，而且也不符合我们的分工需求。一般的做法是利
用权限的设置，依工作性质分类，让特殊身份的用户成为同一个工作组，并设置工作组权限。例如：要wwwadm这位用户负责管理网站数据，一般Apache
Web
Server的进程httpd的所有者是www，您可以设置用户wwwadm与www为同一工作组，并设置Apache默认存放网页目录/usr
/local/httpd/htdocs的工作组权限为可读、可写、可执行，这样属于此工作组的每位用户就可以进行网页的管理了。</p>
<p>　　但这并不是最好的解决办法，例如管理员想授予一个普通用户关机的权限，这时使用上述的办法就不是很理想。这时您也许会想，我只让这个用户可以以
root身份执行shutdown命令就行了。完全没错，可惜在通常的Linux系统中无法实现这一功能，不过已经有了工具可以实现这样的功能——
sudo。</p>
<p>　　sudo通过维护一个特权到用户名映射的数据库将特权分配给不同的用户，这些特权可由数据库中所列的一些不同的命令来识别。为了获得某一特权
项，有资格的用户只需简单地在命令行输入sudo与命令名之后，按照提示再次输入口令（用户自己的口令，不是root用户口令）。例如，sudo允许普通
用户格式化磁盘，但是却没有赋予其他的root用户特权。</p>
<p>1、sudo工具由文件/etc/sudoers进行配置，该文件包含所有可以访问sudo工具的用户列表并定义了他们的特权。一个典型的/etc/sudoers条目如下：</p>
<p>　　<br>
liming ALL=(ALL) ALL</p>
<p><br>
这个条目使得用户liming作为超级用户访问所有应用程序，如用户liming需要作为超级用户运行命令，他只需简单地在命令前加上前缀sudo。因此，要以root用户的身份执行命令format，liming可以输入如下命令：</p>
<p>　　<br>
# sudo /usr/sbin/useradd sam</p>
<p><br>
注意：命令要写绝对路径，/usr/sbin默认不在普通用户的搜索路径中，或者加入此路径：PATH=$PATH:/usr/sbin;export PATH。另外，不同系统命令的路径不尽相同，可以使用命令&#8220;whereis 命令名&#8221;来查找其路径。</p>
<p>　　这时会显示下面的输出结果：</p>
<p>　　We trust you have received the usual lecture from the local System</p>
<p>　　Administrator. It usually boils down to these two things:</p>
<p>　　#1) Respect the privacy of others.</p>
<p>　　#2) Think before you type.</p>
<p>　　Password:</p>
<p><br>
如果liming正确地输入了口令，命令useradd将会以root用户身份执行。</p>
<p>　　注意：配置文件/etc/sudoers必须使用命令 Visudo来编辑。</p>
<p>　　只要把相应的用户名、主机名和许可的命令列表以标准的格式加入到文件/etc/sudoers，并保存就可以生效，再看一个例子。</p>
<p>2、例子：管理员需要允许gem用户在主机sun上执行reboot和shutdown命令，在/etc/sudoers中加入：</p>
<p>　　<br>
gem sun=/usr/sbin/reboot，/usr/sbin/shutdown</p>
<p><br>
注意：命令一定要使用绝对路径，以避免其他目录的同名命令被执行，从而造成安全隐患。</p>
<p>　　然后保存退出，gem用户想执行reboot命令时，只要在提示符下运行下列命令：</p>
<p>　　<br>
$ sudo /usr/sbin/reboot</p>
<p><br>
输入正确的密码，就可以重启服务器了。</p>
<p>　　如果您想对一组用户进行定义，可以在组名前加上%，对其进行设置，如：</p>
<p>　　<br>
%cuug ALL=(ALL) ALL</p>
<p><br>
3、另外，还可以利用别名来简化配置文件。别名类似组的概念，有用户别名、主机别名和命令别名。多个用户可以首先用一个别名来定义，然后在规定他们可以执
行什么命令的时候使用别名就可以了，这个配置对所有用户都生效。主机别名和命令别名也是如此。注意使用前先要在/etc/sudoers中定
义：User_Alias, Host_Alias, Cmnd_Alias项，在其后面加入相应的名称，也以逗号分隔开就可以了，举例如下：</p>
<p>　　Host_Alias SERVER=no1</p>
<p>　　User_Alias ADMINS=liming，gem</p>
<p>　　Cmnd_Alias SHUTDOWN=/usr/sbin/halt，/usr/sbin/shutdown，/usr/sbin/reboot</p>
<p>　　ADMINS SERVER=SHUTDOWN</p>
<p><br>
4、再看这个例子：</p>
<p>　　<br>
ADMINS ALL=(ALL) NOPASSWD: ALL</p>
<p><br>
表示允许ADMINS不用口令执行一切操作，其中&#8220;NOPASSWD:&#8221;项定义了用户执行操作时不需要输入口令。</p>
<p>5、sudo命令还可以加上一些参数，完成一些辅助的功能，如</p>
<p>　　<br>
$ sudo &#8211;l</p>
<p><br>
会显示出类似这样的信息：</p>
<p>　　User liming may run the following commands on this host:</p>
<p>　　(root) /usr/sbin/reboot</p>
<p><br>
说明root允许用户liming执行/usr/sbin/reboot命令。这个参数可以使用户查看自己目前可以在sudo中执行哪些命令。</p>
<p>6、在命令提示符下键入sudo命令会列出所有参数，其他一些参数如下：</p>
<p>　　-V 显示版本编号。</p>
<p>　　-h 显示sudo命令的使用参数。</p>
<p>　　-v 因为sudo在第一次执行时或是在N分钟内没有执行（N预设为5）会询问密码。这个参数是重新做一次确认，如果超过N分钟，也会问密码。</p>
<p>　　-k 将会强迫使用者在下一次执行sudo时询问密码（不论有没有超过N分钟）。</p>
<p>　　-b 将要执行的命令放在背景执行。</p>
<p>　　-p prompt 可以更改问密码的提示语，其中%u会替换为使用者的账号名称，%h会显示主机名称。</p>
<p>　　-u username/#uid 不加此参数，代表要以root的身份执行命令，而加了此参数，可以以username的身份执行命令（#uid为该username的UID）。</p>
<p>　　-s 执行环境变量中的 SHELL 所指定的 Shell ，或是 /etc/passwd 里所指定的 Shell。</p>
<p>　　-H 将环境变量中的HOME（宿主目录）指定为要变更身份的使用者的宿主目录。（如不加-u参数就是系统管理者root。）</p>
<p><br>
要以系统管理者身份（或以-u更改为其他人）执行的命令。</p><img src ="http://www.cppblog.com/mydriverc/aggbug/98054.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-07 23:39 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/07/98054.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在裸设备上面安装oracle10g</title><link>http://www.cppblog.com/mydriverc/archive/2009/10/07/98052.html</link><dc:creator>旅途</dc:creator><author>旅途</author><pubDate>Wed, 07 Oct 2009 15:21:00 GMT</pubDate><guid>http://www.cppblog.com/mydriverc/archive/2009/10/07/98052.html</guid><wfw:comment>http://www.cppblog.com/mydriverc/comments/98052.html</wfw:comment><comments>http://www.cppblog.com/mydriverc/archive/2009/10/07/98052.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mydriverc/comments/commentRss/98052.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mydriverc/services/trackbacks/98052.html</trackback:ping><description><![CDATA[<p style="text-indent: 2em;">原文：<a  href="http://blog.chinaunix.net/u1/59074/showart_1095667.html">http://blog.chinaunix.net/u1/59074/showart_1095667.html</a></p>
<p style="text-indent: 2em;">因为是第一次在裸设备上面安装数据库，所以有很多知识点还是没有学到位，经过自己的多方琢磨，深入思考，问题终于解决，现总结安装步骤如下： </p>
<p style="text-indent: 2em;">第一步：创建裸设备。 </p>
<p style="text-indent: 2em;">按照以下步骤执行： </p>
<p style="text-indent: 2em;">我的实验机器上存在三块硬盘，sda，sdb，sdc。其中sda只用来安装了操作系统，以及应用软件，另外两块硬盘准备用来做裸设备存储数据。 </p>
<p style="text-indent: 2em;">为sdb划分分区，这块硬盘用来存放数据库系统文件system，sysaux等等 </p>
<p style="text-indent: 2em;">[root@pora ~]# fdisk /dev/sdb</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">Command (m for help): p&nbsp;&nbsp;&nbsp;&nbsp;查看分区情况</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">Disk /dev/sdb: 5368 MB, 5368709120 bytes</p>
<p style="text-indent: 2em;">255 heads, 63 sectors/track, 652 cylinders</p>
<p style="text-indent: 2em;">Units = cylinders of 16065 * 512 = 8225280 bytes</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">&nbsp;&nbsp; Device Boot&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Start&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Blocks&nbsp;&nbsp; Id&nbsp; System</p>
<p style="text-indent: 2em;">/dev/sdb1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 652&nbsp;&nbsp;&nbsp;&nbsp; 5237158+&nbsp;&nbsp; 5&nbsp; Extended</p>
<p style="text-indent: 2em;">/dev/sdb5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 13&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 104359+&nbsp; 83&nbsp; Linux&nbsp;&nbsp;&nbsp; control01</p>
<p style="text-indent: 2em;">/dev/sdb6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 14&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 26&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 104391&nbsp;&nbsp; 83&nbsp; Linux&nbsp;&nbsp;&nbsp; control02</p>
<p style="text-indent: 2em;">/dev/sdb7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 27&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 39&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 104391&nbsp;&nbsp; 83&nbsp; Linux&nbsp;&nbsp;&nbsp; control03</p>
<p style="text-indent: 2em;">/dev/sdb8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 40&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 52&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 104391&nbsp;&nbsp; 83&nbsp; Linux&nbsp;&nbsp;&nbsp;&nbsp;redo01</p>
<p style="text-indent: 2em;">/dev/sdb9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 53&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 59&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 56196&nbsp;&nbsp; 83&nbsp; Linux&nbsp;&nbsp;&nbsp;&nbsp; redo02</p>
<p style="text-indent: 2em;">/dev/sdb10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 60&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 182&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 987966&nbsp;&nbsp; 83&nbsp; Linux&nbsp;&nbsp; system</p>
<p style="text-indent: 2em;">/dev/sdb11&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 183&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 305&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 987966&nbsp;&nbsp; 83&nbsp; Linux&nbsp;&nbsp;sysaux</p>
<p style="text-indent: 2em;">/dev/sdb12&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 306&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 428&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 987966&nbsp;&nbsp; 83&nbsp; Linux&nbsp; undotbs1</p>
<p style="text-indent: 2em;">/dev/sdb13&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 429&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 652&nbsp;&nbsp;&nbsp;&nbsp; 1799248+&nbsp; 83&nbsp; Linux temp </p>
<p style="text-indent: 2em;">根据硬盘大小分别划分不同大小的区来作为每个文件的存储，这里用红色字体标识出来的内容为注释。 </p>
<p style="text-indent: 2em;">具体如何利用fdisk来划分区，这里就不详细介绍了，可以参考相关资料。 </p>
<p style="text-indent: 2em;">[root@pora ~]# fdisk /dev/sdb</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">Command (m for help):&nbsp;n&nbsp;&nbsp;&nbsp;&nbsp;创建分区 </p>
<p style="text-indent: 2em;">Command action</p>
<p style="text-indent: 2em;">&nbsp;&nbsp; l&nbsp;&nbsp; logical (5 or over)</p>
<p style="text-indent: 2em;">&nbsp;&nbsp; p&nbsp;&nbsp; primary partition (1-4) </p>
<p style="text-indent: 2em;">这里选择&nbsp;l 创建逻辑分区 </p>
<p style="text-indent: 2em;">First cylinder (1-261, default 1):&nbsp;&nbsp;&nbsp; </p>
<p style="text-indent: 2em;">Using default value 1</p>
<p style="text-indent: 2em;">Last cylinder or +size or +sizeM or +sizeK (1-261, default 261): +1000M&nbsp;&nbsp; 创建1G的分区 </p>
<p style="text-indent: 2em;">Command (m for help): w</p>
<p style="text-indent: 2em;">The partition table has been altered!</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">Calling ioctl() to re-read partition table.</p>
<p style="text-indent: 2em;">Syncing disks.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 保存分区表，同步到硬盘 </p>
<p style="text-indent: 2em;">同理使用fdisk 为sdc这块硬盘划分相应的分区，这块硬盘主要用来存放业务数据。 </p>
<p style="text-indent: 2em;">创建完所有分区以后，我们使用如下命令来查看： </p>
<p style="text-indent: 2em;">[root@pora ~]# fdisk -l</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">Disk /dev/sda: 10.7 GB, 10737418240 bytes</p>
<p style="text-indent: 2em;">255 heads, 63 sectors/track, 1305 cylinders</p>
<p style="text-indent: 2em;">Units = cylinders of 16065 * 512 = 8225280 bytes</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">&nbsp;&nbsp; Device Boot&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Start&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Blocks&nbsp;&nbsp; Id&nbsp; System</p>
<p style="text-indent: 2em;">/dev/sda1&nbsp;&nbsp; *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1177&nbsp;&nbsp;&nbsp;&nbsp; 9454221&nbsp;&nbsp; 83&nbsp; Linux</p>
<p style="text-indent: 2em;">/dev/sda2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1178&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1304&nbsp;&nbsp;&nbsp;&nbsp; 1020127+&nbsp; 82&nbsp; Linux swap</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">Disk /dev/sdb: 5368 MB, 5368709120 bytes</p>
<p style="text-indent: 2em;">255 heads, 63 sectors/track, 652 cylinders</p>
<p style="text-indent: 2em;">Units = cylinders of 16065 * 512 = 8225280 bytes</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">&nbsp;&nbsp; Device Boot&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Start&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Blocks&nbsp;&nbsp; Id&nbsp; System</p>
<p style="text-indent: 2em;">/dev/sdb1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 652&nbsp;&nbsp;&nbsp;&nbsp; 5237158+&nbsp;&nbsp; 5&nbsp; Extended</p>
<p style="text-indent: 2em;">/dev/sdb5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 13&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 104359+&nbsp; 83&nbsp; Linux</p>
<p style="text-indent: 2em;">/dev/sdb6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 14&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 26&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 104391&nbsp;&nbsp; 83&nbsp; Linux</p>
<p style="text-indent: 2em;">/dev/sdb7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 27&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 39&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 104391&nbsp;&nbsp; 83&nbsp; Linux</p>
<p style="text-indent: 2em;">/dev/sdb8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 40&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 52&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 104391&nbsp;&nbsp; 83&nbsp; Linux</p>
<p style="text-indent: 2em;">/dev/sdb9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 53&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 59&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 56196&nbsp;&nbsp; 83&nbsp; Linux</p>
<p style="text-indent: 2em;">/dev/sdb10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 60&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 182&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 987966&nbsp;&nbsp; 83&nbsp; Linux</p>
<p style="text-indent: 2em;">/dev/sdb11&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 183&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 305&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 987966&nbsp;&nbsp; 83&nbsp; Linux</p>
<p style="text-indent: 2em;">/dev/sdb12&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 306&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 428&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 987966&nbsp;&nbsp; 83&nbsp; Linux</p>
<p style="text-indent: 2em;">/dev/sdb13&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 429&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 652&nbsp;&nbsp;&nbsp;&nbsp; 1799248+&nbsp; 83&nbsp; Linux</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">Disk /dev/sdc: 5368 MB, 5368709120 bytes</p>
<p style="text-indent: 2em;">255 heads, 63 sectors/track, 652 cylinders</p>
<p style="text-indent: 2em;">Units = cylinders of 16065 * 512 = 8225280 bytes</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">&nbsp;&nbsp; Device Boot&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Start&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Blocks&nbsp;&nbsp; Id&nbsp; System</p>
<p style="text-indent: 2em;">/dev/sdc1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 652&nbsp;&nbsp;&nbsp;&nbsp; 5237158+&nbsp;&nbsp; 5&nbsp; Extended</p>
<p style="text-indent: 2em;">/dev/sdc5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 123&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 987934+&nbsp; 83&nbsp; Linux</p>
<p style="text-indent: 2em;">/dev/sdc6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 124&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 246&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 987966&nbsp;&nbsp; 83&nbsp; Linux</p>
<p style="text-indent: 2em;">/dev/sdc7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 247&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 369&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 987966&nbsp;&nbsp; 83&nbsp; Linux</p>
<p style="text-indent: 2em;">/dev/sdc8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 370&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 492&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 987966&nbsp;&nbsp; 83&nbsp; Linux</p>
<p style="text-indent: 2em;">/dev/sdc9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 493&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 620&nbsp;&nbsp;&nbsp;&nbsp; 1028128+&nbsp; 83&nbsp; Linux</p>
<p style="text-indent: 2em;">/dev/sdc10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 621&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 652&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 257008+&nbsp; 83&nbsp; Linux </p>
<p style="text-indent: 2em;">第二步：为裸设备建立映射关系 </p>
<p style="text-indent: 2em;">#vi /etc/sysconfig/rawdevices&nbsp;&nbsp;&nbsp; 这个文件用来在启动的时候加载裸设备 </p>
<p style="text-indent: 2em;">内容如下： </p>
<p style="text-indent: 2em;">/dev/raw/raw1 /dev/sdb5</p>
<p style="text-indent: 2em;">/dev/raw/raw2 /dev/sdb6</p>
<p style="text-indent: 2em;">/dev/raw/raw3 /dev/sdb7</p>
<p style="text-indent: 2em;">/dev/raw/raw4 /dev/sdb8</p>
<p style="text-indent: 2em;">/dev/raw/raw5 /dev/sdb9</p>
<p style="text-indent: 2em;">/dev/raw/raw6 /dev/sdb10</p>
<p style="text-indent: 2em;">/dev/raw/raw7 /dev/sdb11</p>
<p style="text-indent: 2em;">/dev/raw/raw8 /dev/sdb12</p>
<p style="text-indent: 2em;">/dev/raw/raw9 /dev/sdc5</p>
<p style="text-indent: 2em;">/dev/raw/raw10 /dev/sdc6</p>
<p style="text-indent: 2em;">/dev/raw/raw11 /dev/sdc7</p>
<p style="text-indent: 2em;">/dev/raw/raw12 /dev/sdc8</p>
<p style="text-indent: 2em;">/dev/raw/raw13 /dev/sdc9</p>
<p style="text-indent: 2em;">/dev/raw/raw14 /dev/sdc10 </p>
<p style="text-indent: 2em;">建立链接关系 </p>
<p style="text-indent: 2em;">ln -s /dev/raw/raw1 /oracle/oradata/orcl/control01</p>
<p style="text-indent: 2em;">ln -s /dev/raw/raw2 /oracle/oradata/orcl/control02</p>
<p style="text-indent: 2em;">ln -s /dev/raw/raw3 /oracle/oradata/orcl/control03</p>
<p style="text-indent: 2em;">ln -s /dev/raw/raw4 /oracle/oradata/orcl/redo01</p>
<p style="text-indent: 2em;">ln -s /dev/raw/raw5 /oracle/oradata/orcl/redo02</p>
<p style="text-indent: 2em;">ln -s /dev/raw/raw6 /oracle/oradata/orcl/system</p>
<p style="text-indent: 2em;">ln -s /dev/raw/raw7 /oracle/oradata/orcl/sysaux</p>
<p style="text-indent: 2em;">ln -s /dev/raw/raw8 /oracle/oradata/orcl/undotbs1</p>
<p style="text-indent: 2em;">ln -s /dev/raw/raw9 /oracle/oradata/orcl/temp</p>
<p style="text-indent: 2em;">ln -s /dev/raw/raw10 /oracle/oradata/orcl/users</p>
<p style="text-indent: 2em;">ln -s /dev/raw/raw11 /oracle/oradata/orcl/data</p>
<p style="text-indent: 2em;">ln -s /dev/raw/raw12 /oracle/oradata/orcl/spfile </p>
<p style="text-indent: 2em;">加载裸设备 </p>
<p style="text-indent: 2em;">#/sbin/service rawdevices restart </p>
<p style="text-indent: 2em;">第三步：安装oracle软件 </p>
<p style="text-indent: 2em;">1.创建用户，赋予权限 </p>
<p style="text-indent: 2em;">#groupadd dba </p>
<p style="text-indent: 2em;">#useradd oracle -G dba </p>
<p style="text-indent: 2em;">#passwd oracle </p>
<p style="text-indent: 2em;">密码设置为: oracle </p>
<p style="text-indent: 2em;">#mkdir /oracle </p>
<p style="text-indent: 2em;">#chown oracle:dba /oracle </p>
<p style="text-indent: 2em;">#chmod -R 755 /oracle </p>
<p style="text-indent: 2em;">2.配置环境变量 </p>
<p style="text-indent: 2em;">#vi /home/oracle/.bash_profile </p>
<p style="text-indent: 2em;">内容如下： </p>
<p style="text-indent: 2em;">ORACLE_SID=orcl</p>
<p style="text-indent: 2em;">ORACLE_BASE=/oracle</p>
<p style="text-indent: 2em;">ORACLE_HOME=/oracle/ora10g</p>
<p style="text-indent: 2em;">PATH=$ORACLE_HOME/bin:$PATH:.</p>
<p style="text-indent: 2em;">LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:/usr/local/lib</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">export ORACLE_SID ORACLE_BASE ORACLE_HOME PATH LD_LIBRARY_PATH </p>
<p style="text-indent: 2em;">以oracle用户登录，执行以下操作 </p>
<p style="text-indent: 2em;">$mkdir /oracle/ora10g </p>
<p style="text-indent: 2em;">$mkdir /oracle/arch </p>
<p style="text-indent: 2em;">$su - </p>
<p style="text-indent: 2em;">#xhost + </p>
<p style="text-indent: 2em;">找到安装包所在目录，执行runInstaller </p>
<p style="text-indent: 2em;">$./runInstaller </p>
<p style="text-indent: 2em;">按照正常步骤安装oracle软件，但是不需要创建数据库。 </p>
<p style="text-indent: 2em;">创建oracle裸设备文件 </p>
<p style="text-indent: 2em;">#vi /home/oracle/dbca.conf </p>
<p style="text-indent: 2em;">内容如下： </p>
<p style="text-indent: 2em;">spfile = /oracle/oradata/orcl/spfile</p>
<p style="text-indent: 2em;">system = /oracle/oradata/orcl/system</p>
<p style="text-indent: 2em;">sysaux = /oracle/oradata/orcl/sysaux</p>
<p style="text-indent: 2em;">undotbs1= /oracle/oradata/orcl/undotbs1</p>
<p style="text-indent: 2em;">data =&nbsp;&nbsp; /oracle/oradata/orcl/data</p>
<p style="text-indent: 2em;">temp&nbsp;&nbsp;&nbsp; = /oracle/oradata/orcl/temp</p>
<p style="text-indent: 2em;">users&nbsp;&nbsp;&nbsp; = /oracle/oradata/orcl/users</p>
<p style="text-indent: 2em;">redo1_1&nbsp;&nbsp; = /oracle/oradata/orcl/redo01</p>
<p style="text-indent: 2em;">redo1_2&nbsp;&nbsp; = /oracle/oradata/orcl/redo02</p>
<p style="text-indent: 2em;">control1= /oracle/oradata/orcl/control01</p>
<p style="text-indent: 2em;">control2= /oracle/oradata/orcl/control02</p>
<p style="text-indent: 2em;">control3= /oracle/oradata/orcl/control03 </p>
<p style="text-indent: 2em;">第四步：创建数据库 </p>
<p style="text-indent: 2em;">$dbca </p>
<p style="text-indent: 2em;">在选择存储设备的时候，我们选择第三项Raw Devices,然后选中&#8220;specify Raw Devices Mapping File&#8221;复选框，点击&#8220;Browse&#8221;按钮，选择上一步我们创建好的裸设备文件/home/oracle/dbca.conf, </p>
<p style="text-indent: 2em;">然后点击&#8220;next&#8221;,配置相应的参数，在配置enable archiving的时候，选择归档日志的存放目录为/oracle/arch。 </p>
<p style="text-indent: 2em;">后面的步骤不详细列举了，希望大家自己去琢磨，一直到创建数据库完成。 </p>
<p style="text-indent: 2em;">第五步：测试数据库 [oracle@pora ~]$ sqlplus / as sysdba</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jul 17 14:24:51 2008</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">Copyright (c) 1982, 2005, Oracle.&nbsp; All rights reserved.</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">Connected to:</p>
<p style="text-indent: 2em;">Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production</p>
<p style="text-indent: 2em;">With the Partitioning, OLAP and Data Mining options</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">SQL&gt; select status from v$instance;</p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">STATUS</p>
<p style="text-indent: 2em;">------------</p>
<p style="text-indent: 2em;">OPEN </p><img src ="http://www.cppblog.com/mydriverc/aggbug/98052.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mydriverc/" target="_blank">旅途</a> 2009-10-07 23:21 <a href="http://www.cppblog.com/mydriverc/archive/2009/10/07/98052.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>