RHCE学习笔记

RHCE学习笔记

 

RH033 Red Hat Enterprise Linux Essentials

 

一、Running Commands and Getting Help

1、设置系统时间

date -s 05/27/2013

date -s 13:12:00

 

2、The man Command

(1)格式

man passwd  = man1 passwd   :User commands

man 5 passwd                 :File format

man 8 lvm                    :Adminstrator commands

(2)man pages

/<keyword>:man中查找所有<keyword>

n/N:下一个/上一个

q:退出man

man -k <keyword>:查找所有包含<keyword>的命令

 

3、The info Command = web man

tab:movethe next link

n:下一小节

p:上一小节

u:上一层小节

s[<text>]:searchfor text

q:退出

 

二、Browsing the Filesystem

1、mountpoints

/media:floppy and CDRom

/mnt

 

2、Important Directories

/etc:systemconfig files

/boot:Kerneland bootloader

/dev:device

/usr:programs

/varand /srv:server data

/proc:systeminformation,是一个虚拟目录

 

3、Current Working Directory

pwd:Displaythe path

 

4、Copying Files and Directories

(1)copy file

cp[option] file destination

cp/tmp/abc.txt /doc

cp –p/tmp/abc.txt /doc :保留所时间戳

 

(2)copy directory

cp –r/tmp  /doc

cp  -r –p /tmp /doc:保留所时间戳

or

cp –a /tmp/doc

 

(3)copy more file

cpabc.txt dd.txt /doc

 

5、Moving and Renaming Files and Directories

(1)move or rename file

mv[option] file destination

mv/doc/aaa.txt /doc/bbb.txt  : rename

mv/doc/bbb.txt /tmp/aaa.txt

mv/doc/bbb.txt /tmp

 

(2)move or rename Directory

mv jpgcalendar   :将目录jpg改为calendar

mv jpgdoc        :将目录jpg移入doc中

 

(3)move more file

mv/doc/aa.txt /doc/bb.txt /jpg

 

6、Creating and Removing Files

(1) Removing Files

rm[options] filenames

-i:interactive(确认信息)

-r:recursive

-f:force

 

rmabc.txt = rm –i abc.txt

rm –fabc.txt

(2) Removing Directory

rmdirjpg      :jpg必须为空目录

rm –r  jpg    :jpg可不为空

rm –f  jpg

 

(3)Creating Files

touchfilenames

touch/tmp/aaa.txt

 

(4)Createing Directory

mkdir/tmp/doc

 

(5)Determining File Content

file[options] filename(s)

filedoc/aaa.txt

 

(6)Viewing an Entire Text File

(i)cat(显示文件所有内容)

cataaa.txt

cat –Aaaa.txt    :会出现换行符

cat –saaa.txt    :将2行以上的空白行合并为一个空白行

cat –baaa.txt    :显示行号

(ii)less(分页显示文件内容)

less aaa.txt

/text  - search for text

n      - next match

v      - open file in text editor

i      - insert mode

q      - quit

 

三、The bash Shell

1、wildcard(通配符)

*      : zero or more characters

?      : any single character

[a-z]  : a range of characters

[^a-z]: all except the range(除外)

 

lstest[1-2].*  : test1.txt test2.mp3

lstest[^1].*   : test2.mp3 test3.txt

2、 history(历史指令)

history: 列出所有历史指令

!76    : 执行第76号历史指令  如:passwd--status user2

^2^1    :将上一个指令中的2改为1 :passwd --status user1

         ping 192.168.0.196

         ^196^1

         ping 192.168.0.1

3、Tilde(~)

cd~  :回到当前用户的home目录

ce~user1 :回到user1的home目录(只有root才有权限进入其它用户的home目录)

 

4、{}

touch{a,b}       : create file a and b

toucha{a,b}      : create file aa and ab

touch{a,b}.{1,2} : create file a.1  a.2  b.1 and b.2

 

5、Command output :在命令中输出其它命令的结果

``or$() : ``为键盘~下的`

echo “Hostname : `hostname`”

ehco “Hostname : $(hostname)”

 

6、重定向 > >>  <

>  : 输出重定向(覆盖 overwrite)

>>:输出重定向(append)

<  : 输入重定向

 

0 :standard  input

1 :standard  output(默认)

2 : standard  error

 

find/etc –namepasswd 1 > stdout   = find /etc –namepasswd > stdout

find/etc –name passwd2 > stderr

find/etc –namepasswd 2 > errs 1 > output :错误导出到errs,输出导出到output

find/etc –namepasswd > alloutput 2 >&1 : 错误和输出都导出到alloutput

find/etc –namepasswd &> alloutput : &表示0,1,2..

 

tr'A-Z' 'a-z' < .bash_profile : 将.bash_profile中所有大写字母改为小写字母

 

7、cut : 显示某列信息

-f :specifies field or column --指定字段或列

-d :specifies field delimiter(Default is TAB) --指定分隔符

-c :cuts by characters  --显示指定位置的字符

 

cat/etc/passwd

    root:x:0:0:root:/root:/bin/bash

    bin:x:1:1:bin:/bin:/sbin/nologin

    daemon:x:2:2:daemon:/sbin:/sbin/nologin

cut -f3-d: /etc/passwd

    0

    1

    2

cut-c4-8 /etc/passwd  --显示第4列到第8列的字符

    t:x:0

    :x:1:

    mon:x

 

8、sort :排序,但不改变文件内容

-r : 反向排列

-f : 不区分大小写

-u : 唯一,去重 unique

-t : 设定栏位之间的间隔符

-n : 按数值排列

-k : 按指定列排序

 

sort-ruf aaa.txt

sort-t: -k3 -n /etc/passwd

 

9、Pipes |

ls -l/etc | less

cut -f1-d: /etc/passwd | sort -r | less

 

10、mail

SendingMail:

mail -s "1st mail" user2 回车输入内容 回车 .(一定在第一列,表示mail结束) Cc:回车发送

ReadingMail:

cat /var/spool/mail/user2

or

mail (x离开: 邮件不删除,q离开:删除阅读过的邮件,将邮件移到~user2/mbox)

ls -l | mail -s "3rd mail" user2 : 将ls -l的内容用邮件发送给user2

 

11、xargs

catdelete_file.txt | xargs rm -f : 无提示信息的删除delete_file.txt文件中文件名所对映的文件

delete_file.txt的内容:

f1.txt

f2.txt

f3.txt

 

12、tee :资料分流

cut -f1-d: /etc/passwd | tee cut.file |sort | tee sort.file | less :将cut的内容导出到cut.file,然后排列,并将排列后的内容导出到sort.file中,并在桌面一面一面的显示

 

四、Users Groups and Permissions

1、User

less/etc/passwd

用户名:有无密码(x有,空无) :

uid :gid : 说明 :home目录   :  默认shellu

user1:  x                 : 502 : 503 :      :/home/user1 :  /bin/bash

less/etc/shadow

用户名 : 有无密码($1$开头表示设定好密码,!!开头表示密码未设定)

user1  : $1$dg5H312o$z29/fGPRtpvnKltYZTCRg/ :15854:0:99999:7:::

 

2、Groups

less/etc/group

组名   : 有无密码: gid : 组成员

user1  : x      : 503 :

 

less/etc/gshadow

组名 : 有无密码 : gid : 组成员

dba  :   !     :     : oracle

 

3、File Security

-r :read           (4)

-w :write          (2)

-x :execute        (1)

 - : no permission  (0)

 

4、chmod

chmod[-R] mode file : -R表示将整个目录的文件设定为指定状态

mode:

   u : owner

   g : group

   o : other

   a : all

  

chmodgo+w doc

chmod-R ugo-r doc

chmod-R 754 doc

 

五、vi Editor Basics and Printing

1、Three Modes of vi

(1)Command mode

(2)Insert mode (a or i,ESC退出到Command mode)

(3)Extended mode(:)

 

2、Cursor Movement

  Command mode :

      w: 下一个单词

      b: 上一个单词

      (: 上一个句子

      ): 下一个句子

      {: 上一个段落

      }: 下一个段落

     

3、Entering Insert Mode

  a : append after the cursor

  i : insert before the cursor

  A : append to end of line

  I : insert at beginning of line

  o : open a line below(在光标下方新增空白行)

  O : open a line above(在光标上方新增空白行)

 

4、Change Delete Yank(Copy) and Put(paste): Command mode

                  Change       Delete   Yank(Copy)

Line          :    cc           dd        yy

Letter(字母)  :     cl           dl        yl

Word          :    cw           dw        yw

 

p : 行paste在上方,单字则在光标后面

P :行paste在下方 ,单字则在光标前面

 

5dd : delete5 lines

5yy :copied 5 lines

5x  : delete 5 characters

 

u : 撤消上一个编辑操作 (undo)

U : 行撤消,撤消所有在前一具编辑行上的操作

ctrl +r : 恢复,即回退前一个命令(redo)

 

5、Searching for Text : Command mode

/text :向下查找指定关键字

?text :向上查找指定关键字

 

n :相同方向继续查找

N :相反方向继续查找

 

6、Saving and Quitting : ex mode

:w  : saving(Writing)

:q  : Quitting

:wq :Saving and Quitting

!   : Forcing

 :w!  : Forcing Save

 :q!  : Forcing Quit

   :wq! :Forcing Save and Quit

 

7、Printing in Linux

(1)system-config-printer :  打开打印机设置

(2)lpr(lp) : 打印文件 

lpr abc.txt 

lpr –Pmylp abc.txt  :指定名为mylp的打印机打印

or

lp –dmylp abc.txt

 

(3)lpq(lpstat)  : 查看所有打印机的打印池 ,Queue地址为/var/spool/cpus

lpq  -Pmylp

or

lpstat

 

(4)lprm(cancel) :删除指定jobid的打印文件

lprm 2

or

cancel 2

 

(5)lpmove : 切换打印机打印

lpmove mylp1-9 mylp2 : 将打印机mylp1中的jobid为9的文件切换到mylp2打印

 

(6)lp:插队

lp -i17-q51 : 将jodid为17的文件的优先级设为51(默认为50)

disablemylp1 : 停用mylp1

/user/bin/enablemylp1 : 启用mylp1(首先打印优先级高的文件)

 

rejectmylp1 : 不能向打印机mylp1的池增加打印文件

acceptmylp1 : 可以向打印机mylp1的池添加打印文件

 

(7)Printing Utilities

enscript: Converts text to PostScript(ps)

enscript abc.txt -p abc.ps

ggv : 查看ps or pdf文件

ggv abc.ps  orggv abc.pdf

ps2pdf: ps to pdf converter

ps2pdf abc.ps > abc.pdf

pdf2ps: pdf to ps converter

pdf2ps abc.pdf > abc.ps

mpage :将多页合并为一页打印

mpage -4 abc.ps > mpageabc.ps (4页到1页)

 

六、FileSystem In-Depth

1、ln : 创建快捷方式symboli(or soft) Links(单独的一个文件,指向目标)

ln -ssrcfilename objfilename

ln -stest testlink;

ls -l :可以查看link,

    ls -li Desktop/

ls -i :可以查看inode-no. inode-no对应inode-table(相当于分区表)

 

2、Hard Links : 将多个的文件对应到一个inode-no(ls -i 的inode-no相同)

lndoc/doc1 backup

 

3、The Seven Fundamental Filetypes

- file

ddirectory

lsymbolic link

b blockspecial file(如:/dev/sda1)

ccharacter special file(如:/dev/mice 鼠标、键盘等)

p namedpipe(如:/dev/initctl)

ssocket(如:/dev/gpmctl)

 

4、checking  FreeSpace

  df : 查看目录使用空间情况

  df -h

  df doc

  df -h doc

  du:查看目录中文件使用空间情况

  du -s:查看指定目录总共使用多少空间

  du -h /tmp

  du -sh /tmp

 

5、Removable Media

beforeaccessing, media must be mounted

beforeremoving, media must be unmounted

 

6、Mounting CD and DVD

Gnome/KDEAutomatically Mount /media/cdrom

mkdircdrom

mount/dev/hdc cdrom

ls -lcdrom

umountcdrom = eject cdrom

 

7、mounting USB media

对应设备文件:/dev/sdaX(linux将USB视为一个scsidevices)

Gnome/KDEAutomatically Mount /media/<Device ID>

mount/dev/sda1

 

8、Mounting Floppy Disks

mount  /dev/fd0 /media/floppy/

umount/media/floppy/

9、Formatting Floppy Disks

(1) a low level format:低格

    fdformat /dev/fd0H1440

(2) a filesystem

    mkfs -t ext2 /dev/fd0

    mke2fs /dev/fd0

    mkfs -t vfat /dev/fd0

 

10、tar:打包文件,但不压缩

(1)打包文件

tar cvfarchive_name files....

  -c : creates a new archive

  -v : produces verbose messages:显示打包了的文件

  -f : archived_name is name of new file:f后面跟的是打包文件名

  -p : 保留原属性

  -z : 使用gzip压缩文件

  -j : 使用bzip2压缩文件

tar cvf~/doc.tar doc

tarcvfz ~/doc.tar.gz doc : 使用gzip压缩文件

tarcvfj ~/doc.tar.bz2 doc : 使用bzip2压缩文件

(2)查看打包文件

tar tfarchive_name.tar:只显示清单

tar tvfarchive_name.tar:清单和详细信息

tarztvf arch_name.tar.gz :查看含gzip属性的tar文件

 

(3)解压打包文件

tar xvfarchive_name.tar

  tar zxvf /tmp/etc.tar.gz /tmp

  tar zcvpf /tmp/etc.tar.gz /tmp

 

11、压缩文件

(1)gzip  gunzip

        -v : 显示压缩比

    -c : 保留原文件,新增压缩文件

     gzip filename:只保留压缩文件,原文件删除

       gzip abc.txt : 只剩abc.gz,abc.txt 删除

       gzip -vc abc.txt > abc.gz : abc.txt保留,该命令只能压综文件,不能压缩目录

     gunzip filename

       gunzip abc.gz

   

(2)bzip2  bunzip2

 

七、Configuring the bash Shell

1、查看Variable

set:查看所有变量

env: 查看环境变量

 

2、查看指定变量

echo$ORACLE_HOME

 

3、the PS1 Local Variable

PS1 :sets the prompt(提示符)

    \d : today's date

\h :short hostname

\t:current time

\u:user name

\w:current working directory

\! :thehistory munber of current command

\$:shows $ or #(root)

\l :theshell's terminal device name. ==tty<number>

echo$PS1

    [\u@\h \W]\$

PS1='[\u@\h \w \l \d \t \!]\$'

 

4、Aliases(别名)

aliaslf='ls -laF'

 

nautilus:打开图形文件框

 

八、Advance Topics in Users,Groups and Permissions

1、/etc/passwd /etc/shadow and /etc/group files

/etc/passwd: User Database

/etc/shadow: Password Database,用User ID and Password以 MD-5 hash

/etc/group: Group Database

 

2、Changing Your Identity

passwdusername :只有root可以修改所有用户密码

passwd :修改自已密码

passwd--status username:查看密码状态

 

3、su

suusername : 切换用户,不切换环境变量

su -username : 切换用户,同时切换环境变量

su : 切换到root

su - :切换到root,同时切换环境变量

 

4、User Information Commands

whoami: 查看当前用户

groups: 查看当前用户属于哪些组

id : 查看用户详细信息

users :查看当前登陆系统的用户名

who : 查看当前登陆系统的用户名、登陆时间点、登陆地点

w : 查看当前登陆系统的用户名、登陆时间点、登陆地点、使用的指令、占用的CPU

last : 查看用户的历史登陆时间和reboot的记录

 

5、Default Permissions

DefaultPermissions for file is 666 (ugo:rw-rw-rw-)

DefaultPermissions for directories is 777 (ugo:rwxrwxrwx)

Defaultumask is 002

RootDefault umask is 022

File666 umask 002 = 664 (ugo:rw-rw-r--)

root666 umask 022 = 644 (ugo:rw-r--r--)

File666 umask 033 = 644 (ugo:rw-r--r--)

 

6、Special Permissions(特殊权限)

suid(4): user    s or S  以文件所有者身分执行命令,而不是执行者本身的权限来执行

sgid(2): group   s or S  以文件所在组身分执行命令

sticky(1): other t or T  以文件所在组的other组身分执行命令

 

chmodu+s filename1 

  -rwxr-xr-x --->  rwsr-xr-x

chmodg+s filename2 = chmod 2755 filename2 (2表示g)

  -rwxr-xr-- --->  rwxr-sr-x

chmodo+s filename3

  -rwsr-xr-x --->  rwxr-sr-t

  -rwsr-xr-- --->  rwxr-sr-T

chmod7755 filename4  (第1个7表示4+2+1=suid+sgid+sticky)

  -rwxr-sr-x --->  rwsr-sr-t

 

 

 

 

九、Advanced Users of the vi Editors

1、File Repositioning(文件中快速定位)

  G : go to last line in file

  1G : go to first line in file

  Ctrl+d : go down half a screen

  Ctrl+u : go up half a screen

 

2、Screen Repositioning(屏幕中快速定位)

H : goto first line on screen(high)

M : goto middle lin on screen (middle)

L : goto last line on screen(low)

z+Enter: make current line first line on screen(将光标所在行变为屏幕的第一行)

z-:make current line last line on screen(将光标所在行变为屏幕的最后一行)

 

3、Filtering

   The output of a command can be placed in thefile : 将指令执行的信息插入到当前编辑的文件中

   The data int the file can be used as input :将文件内容当作命令的输入使用

   Examples:

   vi编辑文件时,在CommandMode下输入

   !!ls -l : ls -l的结果插入到光标所在位置

   !!date : date的结果插入到光标所在位置

   !}sort : 光标后的内容排序,也就是将文件内容当成命令的输入在使用

   !}fmt -w60 : 将文件宽度设为60

  

4、Search and Replace (extended mode,也称末行模式last line mode—执行待定命令)

   :s/This/That : 将当前行中第一个的this替换为That

   :s/This/That/g : 将当前行中所有的this替换为That

   :1,10s/This/That/g : 将第1行到第10行中所有的this替换为That

   :1,$s/This/That/g : 将文件中所有的this替换为That. $表示文件最后面,%也是同样功能

   :.,.+10s/This/That/g : 将当前行开始+10行(共11行)中所有的this替换为That.  +表示向下,-表示向上

 

5、Advanced Reading and Saving

   :r file1 : 将file1中内容输入到当前文件中

   :1,20w file2 : 将当前文件中1到20行内容写入file2中(覆盖file2中原有内容)

   :1,$w file3 : 将当前文件中所有内容写入file3中(覆盖file3中原有内容)

   :1,20w>> file4 : 将当前文件中中1到20行内容append到file3中

  

   同时用vi开启多个文件时:

   :n   :  move to the next file

   :rew :  rewind to the first file

   :n#  :  jump to the previous file, thustoggling between two files(两个文件之间互相切换)

 

6、Configuring vi

   :set :  查看基本设备选项

   :setall :查看所有可以设定的设定选项,以no开头的表示没有设定

       nonumber : 表示没有设定启用行号,设定后变为number

       :set number       : 显示行号

       :set nonumber     : 不显示行号    = :set nonu

       :set ignorecase   : 表示设置不区分大小写

       :set noignorecase : 表示设定区分大小写 = :set noic 

       

       

 

十、Introduction to String Processing

1、head

  head file1 : 默认显示文件前10行

  head -n 15 file1 : 显示文件前15行

  head --lines 17 file1 : 显示前17行  

  head -12 file1 : 显法前12行

 

2、tail

  -f : ,持续显示,文件更新后立即显示

  tail file1 : 默认显示文件最后10行

  tail -n 15 file1 : 显示文件最后15行

  tail --lines 17 file1 : 显示最后17行  

  tail -12 file1 : 显法最后12行

  tail -f file1 : 文件更新后立即显示

 

3、wc(字数统计)

  -l : 统计行数(line)

  -w : 统计单词数(word)

  -c : 统计字符数(character)

  wc readme = wc -lwc readme

  cat /etc/passwd | wc -l : 查看系统用户数量

 

4、uniq(去掉文件中相邻的相同的行)

  -c : 查看重复的行有多少

  uniq filename

  uniq -c filename

  所以,可以先sort后,再uniq

  sort filename | uniq = sort -u filename

 

5、Other String Processing Tools

    (1)paste: 将多个文件的内容合并到一个文件中

      paster file1 file2 file3 > merge2  : 水平合并

      =

      cat file1 file2 file3 > merge2     : 垂直合并

    (2)tr : 字符转义器

      tr 'A-Z' 'a-z' < .bash_profile :将bash_profile中所有大写改为小写

     

      cat -A file4 | tr '$' '\r' >file4.txt  : 将file4中$转为\r

          cat -A file4 : 显示file4所有内容,包含段落标记

          unix2dos file4 : 将unix转为dos格式

 

6、Version Comparison with diff

  tail ABC abc : 显示ABC与abc文件

  diff ABC abc : 比较两个文件不一样   = sdiff ABC abc (以|表示不一样)

      1c1 : 表示第1行不一样

      <  :表示在第1个文件中(ABC)

      >  :表示在第2个文件中(abc)

     

7、Spell Checking with aspell(拼写检查)

  aspell check letter   : 以/usr/share/dict/words中的内容为蓝本

  look exer : 查看以exer开头的单词

 

8、Formatting Tools

expandfile > test : 将file中的TAB转化为空格

fmt -u-w50 read   : -u格式化空格的规格(1个空格),-w规定行宽

pr -5/tmp/words | more :  按打印机格式排版(5列)

 

 

 

 

 

RH133 Red Hat Enterprise Linux SystemAdministrator

 

一、Installation

1、Device Node Examples

(1)Block Devices(512/1024 bytes)

/dev/hda: IDE Drives

/dev/sda: SCSI Drives

/dev/fd0: Standard floppy

ls –l /dev/sd*

(2)Character Devices(1 byte)

/dev/tty[0-6]: virtual consoles

/dev/st0      : SCSI tape drive

ls –l /dev/tty* | more

(3)Symbolic links

ls –l /usr/ |grep ^l | more :列出开头为l的文件

 

2、Sample Partition Structure

MBR :512bytes

boot loader : 446bytes

parition table : 64bytes

magic : 2bytes

 

3、Configuring File Systems

Swapspace is typically 2x physical RAM

Typicalmount points : /boot /home /usr /var /tmp /usr/local /opt

 

4、Software RAID

RAID 0: High speed、unsafe  and Size is N

RAID 1: Low speed、 Safe  and Size is N/2

RAID 5: Highter speed than RAID1、Safer than RAID 0 and  N-1

 

5、LVM : Logical Volume Manager

PV(PhysicalVolume) ---> VG(Volume Group) ---> PE(Physical Extent)

 

6、Validating the Installation

dmesgand /var/log/dmesg

/var/log/messages

/root/instll.log

 

7、Post-Install Configuration(system-config-?)

system-config-date  : 打开日期图形设置界面

system-config-display : 打开显示分辩率图形设置界面

system-config-network  : 打开网络图形设置界面

 

 

二、System Initiazation and Services

1、Boot Sequence Overview

BIOS --->MBR --->Kernel --->init

 

2、GRUB  and grub.conf

(1)GRUB : the GRand Unified Bootloader

(2)/boot/grub/grup.conf

default=0: 默认选择第1组(one title)开机

timeout=5: 选择时间为5秒

passwordredhat : 将进入GRUB的密码设为redhat(p进入)

或用grub-md5-crypt加密grub密码

password --md5 $1$94afadfpaT0/tkpLsrhDKgY

hiddenmenu: 隐藏开机选项(windows or linux)

kernel/vmlinuz-2.6.9-5.EL ro root=LABEL=/ rhgb quiet

  ro : read only

  LABEL=/ : root的根目录位置.  =  root=/dev/sda2(/ 所在分区)

rhgb : 以图形界面方式显示开机信息,如以文件显示刚删除rhgb

quiet : 不显示错误信息,如要显示则删除quiet

(3)/sbin/grub-install /dev/had : 重新安装bootloader

(4)edit grub

a :append.只能在ro root=LABEL=/ 后面追加命令,不能修改

grup append> ro root=LABEL=/ 1 :以Single usermode启动

e: edit.在选择需修改的行后,按e修改。

c:command-line

 

3、/etc/inittab :

id:5(initdefault)--->/etc/rc.sysinit--->/etc/rc5.d/* (/etc/rc.local) --->/sbin/mingetty--->/etc/X11/prefdm(ifis 5) or Text Mode(is not 5)

 

4、Run levels

0 : Halt关机(Do not set initdefault to this)

1 :Single user modes,only the root can be logged on,Used to perform Mantenance

  run level 1 : init ---> /etc/rc.sysint--->/etc/rc1.d/*

run level S : init ---> /etc/rc.sysint

run level emergency : init ---> some /etc/rc.sysint

2 :Multi-user,without NFS networking

3 :Full multi-user mode(Includes networking)

4 :Userdefinable,but duplicate of runlevel 3 by default(默认与3相同)

5 :X11(includes networking)

6 :Reboot(Do not set initdefault to this)

 

initnumber : 进入相应的run level,如xll下init 3,则进入textmode

runlevel: 显示前一个级别和当前级别.如5 3 表示从5到3

 

5、/etc/rc.d/rc<5>.d

/etc/init.d/httpdstart  : start http

/etc/init.d/httpdstop   : stop http

/etc/init.d/gpmstart    : start gpm(鼠标)

/etc/init.d/gpmrestart    : restart = reload

/etc/init.d/gpmreload

/etc/init.d/gpmstatus

 

6、Controlling Services

(1)default startup

ntsysv: 设置启动/停止的自动服务(默认只是当前runlevel)

ntsysv –level35 : 设置在runlevel 3和5上的启动/停止的自动服务.

chkconfiggpm –level123 off : 在1、2、3的runlevel上关闭gpm(鼠标)服务

ls –l/etc/rc*.d/*gpm

chkconfiggpm –list : 查看gpm服务在所有runlevel上设定情况

system-config-services: 图形界面下设置启动/停止的自动服务(只能设定345)

(2)manually startup

service: 手动立即启动/停止服务(不建议使用,建议使用/etc/init.d/?? start)

service gpm stop

/etc/init.d/gpm start

chkconfigtelnet off(on)

system-config-services

 

7、System Shutdown

shutdown–h now

halt

poweroff

init 0

 

8、System Reboot

shutdown–r now

reboot

init 6

 

三、Kernel services and Configuration

1、The /proc Filesystem

/procis a virtual filesystem containing information about the running kernel

cat /proc/cpuinfo

cat /proc/meminfo

/procsubdirectories:

/proc/scsi/ 、 /proc/sys/ 、/proc/<PID>/

 

Echo “1” >/proc/sys/net/ipv4/icmp_echo_ignore_all: 禁用icmp包

将/proc/sys/net/ipv4/icmp_echo_ignore_all的内容设为1,禁用icmp包

Echo “0” >/proc/sys/net/ipv4/icmp_echo_ignore_all: 启用icmp包

将/proc/sys/net/ipv4/icmp_echo_ignore_all的内容设为0,启用icmp包

 

2、/proc/sys configuration with sysctl

 修改/proc/sys中的参数,只是临时有效,重启后失效

 Sysctl修改后,永久有效,会写入/etc/sysctl.conf中

 Sysctl –p :显示sysctl.conf中内容

 

3、System Monitoring and Process Control

Top :display snapshot of processes

gonme-system-monitor: display snapshot of processes(图形界面下显示)

Vmstat: reports virtual memory stats

  eg : vmstat

us : user space |  sy : system call  |  id :idle  | wa : waiting

Free :summary of system memory usage

Renice: chang priority of a process

Kill :send system signal to a process

 

四、Filesystem Management

1、Managing Partitions

(1)fdisk

fdisk –l/dev/sda : 查看sda分区

fdisk /dev/sda  : n --> 回车 -->回车-->输入大小 -->w

m :help

p : 查看分区表

(2)partprobe : 重新初始化kernel的partition table(不用reboot)

 

(3)mke2fs [options] device

dumpe2fs/dev/sda1 | more : 查看sda1分区的详细说明

 

-b : 设定Block size的大小,default为1024=1K, 最大为4K.

emke2fs –b 4096/dev/sda1

-c :check the device for bad blocks before creating the filesystem

-i : 设置每个inode的大小

emke2fs –i 4096/dev/sda1

-N : 设定inodes的总数量

emke2fs –N 20000/dev/sda1

-m : 设定分区上保留多少空间给super user(root),default to 5%

emke2fs –m 10/dev/sda1

-L : 设定分区的label

emke2fs –L data/dev/sda1

-j : createan ext3 journal inode and filesystem(ext3格式文件系统)

emke2fs –j/dev/sda1

 

2、Ext3 : journaling ofr ext2 filesystem

ext2转ext3 : tune2fs -j /dev/sda6(资料会保存)

ext3转ext2 : emke2fs  /dev/sda1 (重新格式化)

 

3、Filesystem Labels

e2label/dev/sda1 : 查看sda1的label

e2label/dev/sda1 /date : 设定sda1的label为/data

注意:不要改变sda1至sda5的label,未则可能造成不能开机

4、mount

mkdir/data

mount :查看所有挂载点的信息

mount/dev/sda6 /data

以label名来mount

mount-L /data /data : 将label为/data(第一个) mount 到/data目录(第二个)

 

mountoptions:

mount [-t vfstype] [-o options] device mount_point

-t : vfstype(vfat ext2 ext3 iso9660 ) ,but notnormally needed

mount -t iso9660 -o ro,loop boot.iso /iso : 将boot.iso mount到/iso

-o :

     suid: suid or sgid file modes honored

ro : read only access

rw : read write access

Default option for the ext2/ext3 filesystem:

rw,suid,dev,exec,auto,nouser and async

mount-o remount,ro /data : 将/data目录重新mount为read only模式

mount-o noexex /dev/sda6 /data : mount后,禁止/data目录下文件的执行权限

 

 

5、umount

umountdevice | mount_point

umount/dev/sda6

umount/data

 

6、fuser

-v : 显示哪个所有者或服务正在使用指定目录

fuser -v /data

-k : killprocesses accessing the named file

-m : showall processes using the named filesystems

fuser -km /data

umount /data (当设备忙时,可以先fuser-km 后,umount)

 

7、Connectiong Network Resources

(1)NFS

showmount-e ip : 查看指定ip的共享

showmount -e 192.168.0.144

mount ip:/shared/dir /mnt/nfs : 持载 共享目录

mkdir /mnt/nfs

mount 192.168.0.144:/var/ftp /mnt/nfs

ls -l /mnt/nfs

(2)SMB

smbclient -L ip -N : 查看指定ip的smb共享

smbclient-L 192.168.0.165 -N

mount //ip/share_name /mnt/smb -ousername=account%password

  mkdir /mnt/smb

  mount//192.168.0.165/RHCE /mnt/smb -o username=administrator%123456

  ls /mnt/smb/

 

8、/etc/fstab  : auto mount

cat/etc/fstab

设备

挂载点

文件类型

参数

dump_freq

fsck_order

LABEL=/boot

/boot

ext3

defaults

1

2

tmpfs

/dev/shm

tmpfs

defaults

0

0

devpts

/dev/pts

devpts

gid=5,mode=620

0

0

sysfs

/sys

sysfs

defaults

0

0

proc

/proc

proc

defaults

0

0

/dev/VolGroup00/LogVol01

swap

swap

defaults

0

0

/dev/sdb1

/tools

ext3

defaults

1

2

 

dump_freq:是否备份(0不备份、1每天备份、2每2天备份.....)

fsck_order:自检顺序(0不自检、1(第一个自检)和2(第二个自检)自检、如根分区为1则其它分区只能是2)

 

example:

cp /etc/fstab  /etc/fstab.bak

vi/etc/fstab

yy复制一行

p粘贴

修改为:/dev/sda6  /data   ext3    defaults    1   2

文件系统类型用mount查看

:wq

reboot

 

/etc/mtab: 当前挂载点记录

 

9、auto.master : 监控mount

(1)设定auto.master文件

vi/etc/auto.master

增加:

/mnt/nfs   /etc/auto.nfs  --timeout=60  (60秒无操作自动卸载,auto.nfs可自定义文件名)

:wq

(2)设定auto.nfs

cp/etc/auto.misc /etc/auto.nfs

vi/etc/auto.nfs

新增

server1    -ro,soft,intr      192.168.0.144:/var/ftp

:wq

server1: 自定义名称

soft    : nfs故障时给使用者传回信息

intr    : 允许中断

(3)杳看共享内容

cd/mnt/nfs

ls (无结果)

serviceautofs restart :启动auto.master服务

cd/mnt/nfs

ls (无结果)

cdserver1

ls (有结果)

mount(可看到servier1r的挂载点)

 

10、ext2/ext3 Filesystem Attributes

(1)lsattr: display file attributes

lsattr

lsattr/data

lsattr/data/abc.emp

(2)chattr: changes file attributes

chattr+(-)=attribute file

A : 不修改文件存取的时间

a : 只能append,不能修改以前的内容

d : 备分时,不备份该文件

i : 不能将文件删除和改名

j : 将文件的meta-data记录在ext3的journal内

S : 文件被修改后,立刻将内容写入到磁盘里(否则先buffer)

example:

lsattr test

chattr +a test

lsattr test

cat > test   : Operation notpermitted

cat >> test  :可append

chattr -a test

lsattr test

 

chattr =aAS test  : 在test上设定a、A、S属性

lsattr test

chattr = test  : 取消所有属性

lsattr test

 

11、Virtual Memory

(1)createswap partition

fdisk /dev/sda  :

 n 

回车

+100M  

t(修改partition’s system id)

7(刚建立,是最后一个)

L(查看所有partition’s system id,82为swap)

82

p(查看partition table)

w

partprobe(让partition table立刻生效)

mkswap /dev/sda7  (写入特定的swap识别标识)

vi /etc/fstab

/dev/sda7   swap    swap    defaults    0   0

:wq

  swapon -s (杳看swap启用状态)

swapon -a (启用所有swap分区)

swapon -s (杳看swap启用状态)

 

(2)createswap file

dd if=/dev/zero of=/swapfile bs=1M count=100

dd:Convertand copy file

if:inputfile

/dev/zero:与/dev/null一样是一个伪文件,产生连续不断的二进制零流,写入人的输出会丢失不见. 而从/dev/zero读出一连串的null也比较因难,可通过od或16进制编辑器来做到.主要用来创建一个指定长度的初始化空文件。就像临时交换文件

of:outputfile

bs:blocksize

swapfilesize = bs*count = 1M*100 = 100M

ls -lh/swapfile

mkswap/swapfile  (写入特定的swap识别标识)

vi/etc/fstab

/swapfile   swap    swap    defaults    0   0

:wq

swapon-s (杳看swap启用状态)

swapon-a (启用所有swap分区)

swapon-s (杳看swap启用状态)

 

12、Filesystem Maintenance

(1)fsck: check filesystem

检查之前先umount,检查有问题就会copy到lost+found目录中

umount/data (/data = /dev/sda6)

fsck -y/dev/sda6  :  -y 表示任何问题都回答yes

mount/data

 

(2)sulogin:  系统出现严重错误时,系统会进入sulogin模式

实验:

vi/etc/fstab

将LABLE=/ 修改为LABLE=abc

:wq

reboot

出现错误,系统无法挂载根目录

(ortype Control-D to continue):

输入root的密码

(Repairfilesystem) 1 #   : 进入了sulogin模式

ls(该状态下可能输入指令)

vi/etc/fstab   (readonly mode)

将LABLE=abc 修改为LABLE=/

:wq!  (报错,因为此时要目录的partition是readonly模式挂载)

:q!

mount-o remount ,rw /dev/sda2  : 将根目录/重新挂载为rw

vi/etc/fstab

将LABLE=abc 修改为LABLE=/

:wq!

reboot

 

13、Adding a Drive

实验:

增加10G硬盘一个

fdisk-l检查硬盘,未检测到新硬盘,重启

fdisk-l

fdisk/dev/sdb  输入n/p/1/回车/回车/w

fdisk-l

mkfs -text3 -c /dev/sdb1   //format

cd /

mkdirfujian

mount/dev/sdb1 /fujian

df -h

vi/etc/fstab

文件最后填加以下内容,让系统自动挂载

/dev/sdb1      /fujian      ext3   defaults   1  2

reboot

df -h

 

五、Network Configuration

1、Device Recognition

/etc/modprobe.conf : 为每个网卡定义别名

alias eth0 vmnics

 

2、ifconfig

将eth0的IP设为10.0.1.100(临时有效)

ifconfig eth0 10.0.1.100 netmask 255.0.0.0 broadcast 10.0.1.254

 

3、ifup/ifdown : start or stop network interfaces

ifdowneth0

ifupeth0

 

4、Interface Configuration files

Locaktedin : /etc/sysconfig/network-scripts/

 

ls/etc/sysconfig/network-scripts/ifcfg*

cat/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=none(static、dhcp)

HWADDR=00:50:56:A3:78:BC

ONBOOT=yes(开机启动)

NETMASK=255.255.255.128

IPADDR=192.168.1.144

GATEWAY=192.168.1.254

TYPE=Ethernet

USERCTL=no

IPV6INIT=no

PEERDNS=yes

 

5、Configuration Utilities

(1)netconfig(text)

cd/etc/sysconfig/network-scripts/

lsifcfg*

rmifcfg-eth0

lsifcfg*

 

netconfig   : default is eth0

lsifcfg*

catifcfg-eth0

DHCP:

DEVICE=eth0

BOOTPROTO=dhcp

ONBOOT=yes

Static:

DEVICE=eth0

BOOTPROTO=static

ONBOOT=yes

NETMASK=255.255.255.128

IPADDR=192.168.1.144

GATEWAY=192.168.1.254

ifconfig

ifdowneth0

ifupeth0

ifconfig

 

设定指定网卡:

netconfig --device eth1  : 设定eth1

 

手动设定网卡:

vi ifcfg-eth0

DEVICE=eth0

BOOTPROTO=static

ONBOOT=yes

NETMASK=255.255.255.128

IPADDR=192.168.1.144

GATEWAY=192.168.1.254

:wq

cat ifcfg-eth0

ifconfig

ifdown eth0

ifup eth0

ifconfig

 

(2)system-config-network(Graphical)

neat and system-config-network都可打开网卡设置图形界面

图形界面设置网卡会产生不必要的文件

在sysconfig中查找关键字192.168.1.144的文件

grep -rl 192.168.1.144 /etc/sysconfig

/etc/sysconfig/network-scripts/ifcfg-eth0

/etc/sysconfig/networking/devices/ifcfg-eth0

/etc/sysconfig/networking/profiles/default/ifcfg-eth0

只需保留/etc/sysconfig/network-scripts/ifcfg-eth0就可以了

 

6、Binding Multiple IP Addresses

绑定少量IP:

必须以ifcfg-ethX:xxx形式设定文件

实验:在eth0上增加IP :192.168.1.156

cp ifcfg-eth0 ifcfg-eth0:0

ls ifcfg*

vi ifcfg-eth0:0

修改:DEVICE=eth0:0

IPADDR=192.168.1.156

:wq

cat ifcfg-eth0:0

ifconfig

ifdown eth0

ifup eth0

ifconfig

 

绑定大量IP:

以ifcfg-ethX-rangeX形式设定文件

实验:在eth0上增加10个IP :192.168.1.157-166

cp ifcfg-eth0:0 ifcfg-eth0-range0

ls ifcfg*

vi ifcfg-eth0-range0

修改:DEVICE= eth0-range0

删除IPADDR

IPADDR_START=192.168.1.157

IPADDR_END=192.168.1.166

:wq

cat ifcfg-eth0-range0

ifconfig

ifdown eth0

ifup eth0

ifconfig

 

7、Global Network Parameters

/etc/sysconfig/network

NETWORKING=yes | no

HOSTNAME=<fqdn by default>  ---fqdn : short name + .+ domain name

GATEWAY=<gateway IP>

NISDOMAIN=<nis domain name>

 

8、Static Routes

    系统连接多个网段时,由kernel自动产生route

配置文件:

/etc/sysconfig/network-scripts/route-eth0

图形工具还会将设置写到: 

/etc/sysconfig/networking/devices/route-eth0

Display with:

route -n

netstat -rn

 

Manual set Route:

route add -net 10.0.1.0 netmask 255.255.255.0 gw 192.168.0.144

net:表示加入一整个网段

route-n

  reboot后失效,如要长期有效,则要写入/etc/sysconfig/network-scripts/route-eth0文件中.

   cd /etc/sysconfig/network-scripts/

   vi route-eth0 (不存在,新增)

      10.0.2.0/24 via 192.168.0.144

10.0.3.0/24 via 192.168.0.144

10.0.4.0/24 via 192.168.0.144

       :wq

cat route-eth0

route -n

ifdown eth0

ifup eth0

9、Name Resolution

hostname : 查看主机名,

主机名存放位置:/etc/sysconfig/network

 

10、DNS

hosts文件与DNS

在/etc/nsswitch.conf文件中的设定是默认先搜索/etc/hosts,再查找DNS

将/etc/nsswitch.conf中的hosts:  files dns这行改为hosts:dns files则先搜索DNS

 

11、DNS Client configuration

/etc/resolv.conf

    defines which name servers to use

    servers arc checked in order listed

   

cat /etc/resolv.conf

serch domain.com        : hostname =simple name + domain name(domain.com)

nameserver 192.168.0.1  : DNS server

nameserver 192.168.1.1  : DNS server

 

ping server1时,自动为ping server1.domain.com

 

12、DNS Utilities

(1)host: gather host/domain ifnormation

    host ns1.redhat.com   :显示ns1.redhat.comhas address 66.187.233.210

    host -a redhat.com    : 显示redhat.com主机上的DNS记录

    host -a redhat.com | grep'^[^;]'   : 过滤分号开头的行

 

(2)dig: send queries to name server directly

    dig ns1.redhat.com : 显示redhat.com主机上的DNS记录

    dig ns1.redhat.com | grep'^[^;]'   : 过滤分号开头的行

    dig @ns1.redhat.com mx redhat.com| grep '^[^;]'

        在ns1.redhat.com服务器上查找domain为redhat.com的邮件服务器

        mx : 邮件服务器

 

13、Network Diagnostics

ping : network packet loss and latency measurement tool

traceroute 、mtr : displays network path to adestination

netstat : Multi-purpose network information tool

 

六、RPM and Kickstart

1、 RPM Package Manager

(1)RPMComponents

    local database : /var/lib/rpm

    rpm and related executables

    package files

   

(2)PrimaryFunctions

    install/remove

    query

    verify

    build

   

2、Installing and Removing Software

(1)PrimaryRPM options

    Install : rpm -i(or--install)  ----新旧并存

    Upgrade : rpm -U(or--upgrade)  ----升级旧版本,无旧版本则安装

    Freshen : rpm -F(or--freshen)  ----更新旧版本,无旧版本则不会安装

    Erase   : rpm -e(or --erase)    ----删除

(2)OutputOptions

    -v : 表示输出

    -h : 显示安装进度

   

(3)Example:

   rpm -ivhsysstat-5.0.5-1.i386.rpm   : 安装iostat工具

   rpm -e sysstat                      : 删除sysstat

   rpm -Uvhftp://192.168.0.144/pub/RedHat/RPMS/sysstat*.rpm : 网络安装rpm包

   uname -r  : 查询kernel的版本

 

3、RPM Queries

(1)InstalledPackage Options(已安装)

    rpm -qa               : lists installed packages

    rpm -qf filename      : shows owning package(从哪个包安装的)

    rpm -qi package_name  : general information(列出已安装包的标准详细信息)

    rpm -ql package_name  : lists files in package

 

(2)UninstalledPackage Options(未安装)

    rpm -qip package_file.i386.rpm

    rpm -qlppackage_file.i386.rpm   : 列出rpm包的文件内容

 

4、RPM Verification

Installed RPM file Verification:

rpm -Va  : verifieds all installedRPMs against the RPM database

rpm -V package_name : verifies the installed package_name  against

the RPM database

rpm -Vp package_file.i386.rpm: verifies the installed package_name  

against the package_file

 

5、Other RPM Utilities and Features

(1)rpm2cpio

rpm只能root能用,cpio所有用户可用

rpm2cpio sysstat-5.0.5-1.i386.rpm > sysstat.cpio

cpio -it < sysstat.cpio : 查看sysstat.cpio内有哪些文件,都是以相对路径格式,所以最好是放在单独目录中解压

mkdir sysstat

mv sysstat.cpio sysstat

cd sysstat

cpio -id < sysstat.cpio  : 解压sysstat.cpio

 

(2)rpmdb-redhat: 记录本rpm包依赖性的资料库

(3)system-config-packages: 打开add or Remove Packages图形界面

 

6、Automatic Dependency Resolution(自动安装有依赖性的包)

(1)条件:

用rpmdb-redhat资料库

有依赖性的包必须都在一个目录中

安装时加上-aid参数

(2)Example

rpm -ivh rpmdb-redhat-4-0.20050107.i386.rpm

rpm -ivh xsane-0.92-13.i386.rpm

error : Failed dependencies

Suggested resoltions:

libieee1284-0.2.8-4.i386.rpm

sane-backends-1.0.14-6.i386.rpm

rpm -ivh xsane-0.92-13.i386.rpm --aid

 

7、Using kickstart to Automate Installation(自动安装RHEL)

ks.cfg : 应答配置文件

Example:

system-config-kickstart

error:command not found

system-config-packages

打开add orremove packages,在system的administratortoos中选中system-config-kickstat,Update,

rpm -ivhsystem-config-kickstart-0.2.5.16-12.noarch.rpm

system-config-kickstart

打开Kickstart Configurator对话框,一定要设定root密码

SAVE /root/ks.cfg

也可以直接编辑/root/ks.cfg文件

vi /root/ks.cfg 

 

8、Network Installation Server(网络安装服务器)

(1)Server  : RedHat.iso

(2)Server  : Shares the Redhat.isoDirectory(NFS、FTP、HTTP)

(3)Clients : 放入ks.cfg 的软盘

(4)Clients : 用RedHat.iso启动Linux安装

(5)Clients : Linux安装界面的boot: 输入linux ks=floppy

 

七、User Administrator

1、/etc/passwd

finger username : 显示指定用户的信息

finger oracle

chfn -o value username : 给指定用户加上注解

 chfn -o 在中国 oracle

如果/etc/passwd最后一栏是/sbin/nologin,表示只能从ftp登陆

  ftp192.168.0.144  ftp/ftp登陆

如果/etc/passwd最后一栏是/bin/false,表示只能从发邮件,不能登陆

ls -l /etc/passwd 

-rw-r--r--,必须将read权限开放给所有用户,所有用户登陆时都要读取该文件

chmod 600 /etc/passwd

-rw-------

  user1登陆

error: id cannot find name foruser ID 501

 

2、Adding a New User Account

(1)新增用户:useradd username

  edit /etc/passwd、 /etc/shadow 、/etc/group  (组名=用户名)

  create andpopulate home directory

  set permissionsand ownership

 

useradd user3

cat /etc/passwd

user3:x:503:504::/home/user3:/bin/bash

cat /etc/shadow

user3:!!:15861:0:99999:7:::

cat /etc/group

user3:x:504:

(2)修改密码 :passwd username

passwd user3

cat /etc/shadow

user3:$1$qOfqkG4g$CVBYtVokSSZXDEvxhAGBU/:15861:0:99999:7:::

 

(3)批量建立用户 : newusers

新建newuser文件

vi newuser

格式:

用户名:密码:UID:GID:FullName:HOME:SHELL

user4:user4:505:505::/home/user4:/bin/bash

user5:user5:506:506::/home/user5:/bin/bash

user6:user6:507:507::/home/user6:/bin/bash

cat newuser

newusers newuser

 

3、Group Administrator

(1)groupadd

groupadd group1  : 新增组group1

(2)groupmod

group -n group2 group1 : 将group1重命名为group2

(3)groupdel

groupdel group2 : 删除group2

 

4、Modifying or Deleting User Accounts

(1)edit /etc/passwd

(2) Modifying  User  : usermod

  id user3  : 显示user3的基本资料

 

mkdir /home/user-3

chown user3.user3 /home/user-3 :将user-3目录所有者改为 user3

usermod -d /home/user-3 user3 : 将user3的home目录修改为/home/user-3

 

usermod -G groupname username

usermod -G user3 user1 : 将用户user1加入user3组中

usermod -g groupname username

ussermod -g user3 user1 : 将用户user1的组更改为user3

 

usermod -L user1 : 锁定用户user1

usermod -U user1 : 解锁用户user1

(3)、Deleting User : userdel

userdel  -rusername  (只删除/etc/group中相关组下的成员,不会删除所在组)

userdel -r user3

groupdel  user3 (如果组中没有成员,则可删除)

 

5、Password Aging Policies(密码有效期)

(1)Edit/etc/login.defs

 

(2)chage

格式: chage [options] username

 

cat /etc/shadow

user3:$1$qOfqkG4g$CVBYtVokSSZXDEvxhAGBU/:15861:0:99999:7:::

第一栏 : 用户名

第二栏 : 密码,$1$开头表示密码已设定好,!!表示未设定,!表示锁定不能登陆

第三栏 : 最后一次变更密码的日期,从1970年1月1日开始起算,chage -d

第四栏 : 密码最少要使用多久才能变更,0表示无限制,随时可以更改. chage -m

第五栏 : 密码每隔多久就要变更,99999表示无限制,可以永不变更.chage -M

第六栏 : 密码到期前多久就要提示用户变更密码.

第七栏 : 密码过期多久后,还未更改就锁定用忘户帐号. chage -I

第八栏 : 密码到期时间,sinceJan 1 1970. chage -E

第九栏 :保留

 

chage -l user3 :  查看user3的密码情况

chage -d 20013-06-05 user3 : 将用户user3的密码最后变更日期改为20013-06-05

chage -m 10 user3 : 用户user3最少要在10天后才能变更密码,也就是该密码最少要用10天

chage -M 30 user3 : 用户user3每隔30天就必须变更密码

chage -I 3 user3 : 密码过期3天后,还未更改就锁定用user3帐号

chage -E 2013-08-31 user3 : 设定user3的密码到期日为2013年8月31日

 

6、Login Shell Scripts(用户登陆时执行的shell

用户登陆时:

第一步:系统首先执行/etc/profile,

第二步:/etc/profile执行 /etc/profile.d/下所有shell: /etc/profile.d/*.sh

cat /etc/profile :

for i in /etc/profile.d/*.sh ; do

    if [ -r"$i" ]; then

        if ["$PS1" ]; then

            . $i

        else

            . $i>/dev/null 2>&1

        fi

    fi

done

第三步:系统执行~/.bash_profile

第四步:.bash_profile 执行~/.bashrc

cat ~/.bash_profile

if [ -f ~/.bashrc ]; then

        .~/.bashrc

fi

第五步:.bashrc 执行/etc/bashrc

cat ~/.bashrc

if [ -f /etc/bashrc ]; then

        ./etc/bashrc

fi

 

7、Non Login Shell Scripts(su username)

第一步:执行~/.bashrc

第二步:.bashrc 执行/etc/bashrc

第三步:执行 /etc/profile.d/下所有shell: /etc/profile.d/*.sh

cat /etc/bashrc

if ! shopt -q login_shell ; then # We're not a loginshell

        # Need toredefine pathmunge, it get's undefined at the end of /etc/profile

    pathmunge () {

                if! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then

                        if [ "$2" ="after" ] ; then

                                PATH=$PATH:$1

                       else

                                PATH=$1:$PATH

                       fi

                fi

        }

 

        # Onlydisplay echos from profile.d scripts if we are no login shell

    # andinteractive - otherwise just process them to set envvars

    for i in/etc/profile.d/*.sh; do

        if [ -r"$i" ]; then

            if ["$PS1" ]; then

                .$i

            else

                . $i >/dev/null 2>&1

            fi

        fi

    done

 

        unset i

        unsetpathmunge

fi

 

8、Switching Accounts

su : Non Login Shell Scripts方式切换到root用户

su - : Login Shell Scripts方式切换到root用户

su oracle  : NonLogin Shell Scripts方式切换到oracle用户

su - oracle : Login Shell Scripts方式切换到oracle用户

su username -c command : 以指定user身份执行一次指定的命令

su oracle -c ‘echo $HOME’: 以oracle用户身份执行echo $HOME命令

 

9、sudo(其它用户可以执行root才能执行的命令)

修改/etc/sudoers文件

vi /etc/sudoers : 只能以readonly方式打开文件

visudo /etc/sudoers : 才可以执行write操作

  #User aliasspecification

  User_AliasWWW=www1,www2  : 新增用户别名为WWWADMIN. 并指定用户www1和www2. 命

名是包含大写字母、下划线以及数字,但必须以一个大写字母开头

 

  #Cmnd aliasspecification

  Cmnd_AliasCHttp=/etc/init.d/httpd :新增命令别名WWW执行/etc/init.d/httpd命令.

必须是文件或目录的绝对路径

 

  #User privilegespecification

  root ALL=(ALL)ALL

  WWWALL=CHttp  : WWW在任何地点(ALL)都可以执行命令CHttp

:wq

 

su - www1

sudo /etc/init.d/httpd restart

Password:输入www1的密码

重启httpd服务

 

su - user1

sudo /etc/init.d/httpd restart

Password:输入user1的密码

error : user1 is not in the sudoers file. This incidentwill be reported.

并向root发一封mail

 

exit(回到root)

mail (查看mail)

& 1 : 查看第一封mail,可看到sudo的详细错误

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值