· learnings  · 3 min read

Linux学习日志 Ⅱ

帐户建立

建立组:
Groupadd –g
组建立之后存放在/etc/group里面, 显示出来为:
Group Name: x: Group ID

建立用户:
Useradd –u-g-d

-s-c
Ex.
Useradd –u 1000 –g 751 –d /home/yoh –s /bin/bash –c “yoh” yoh
用户建立之后存放在/etc/passwd里面,显示出来为:
username:x:uid:gid:full-name:home-directory:default-shell
Examples:
n1234567:x:500:600:John Black:/home/n1234567:/bin/bash

建立密码:
Passwd

查看密码:(显示为x的部分)
用root用户进入到目录/etc/shadow, 显示出来为:
用户名:密码:最后更改时间:更改间隔时间:下次更改日期:离更改多少日期警告用户:expire后多少日期被注销:账户使用期限:保留字段

察看用户信息:
Finger

*********************************************
lower IDs (below 500) reserved for system users
Root user has numeric user ID of 0

标准目录结构:
–/bin and /usr/bin store user executable programs
–/sbin and /usr/sbin store system executable programs
–/tmp contains temporary files
–/etc contains configuration files
–/var contains log files, spool files
–/dev Device Files

Block devices read and write blocks of data at a time
eg floppy drives, hard disks
eg device files - /dev/fd0, /dev/hda
Character devices read and write one character at a time
eg printers, terminals
eg device files - /dev/lp0, /dev/tty2
*********************************************

            

            

                  

账户管理

更改权限
“chown”, “chgrp”, “chmod”
●“chown” changes owning user of file or directory
●“chgrp” changes owning group of file or directory
Chgrp
or
Chown user:group

chmod 0740
“chmod u=rwx,g=r

Suspend user account:
passwd –l

Full delete user account
userdel –f –r

***************************************************
Format of listing includes
type    owner  group  other
d/c/b/l   rwx   rwx    rwx

Types of files include
–d: directory, c: character device, b: block device, l: symbolic link

●SetUID/SetGID
–Executes with rights of owner/owning group, instead of executor
●Sticky Bit
–Only owner of file, owner of directory, or root user can delete files within

Special Permissions
●If owner field has “s” in place of “x”, then SetUID executable
●If group field has “s” in place of “x”, then SetGID executable
●If other field has “t” in place of “x”, then sticky

●Permissions can be written as 4 octal digits
●First digit in binary:
–SetUID SetGID Sticky
●Remaining 3 digits in binary correspond to Owner, Group and Other permissions

***************************************************

        

          

Shell Scripts + 定义显示
Vi filename
#! /bin/bash                 所在shell
head –n 1 /etc/passwd    显示开头第一行
tail –n 2 /etc/passwd       显示末尾两行
wc –l /etc/passwd           统计行数
grep –w student             显示有student的文件
>sortedlist                      输出到文件

执行script文件
If executable, type in name of script, if in $PATH
–If not in path, type “./
If not executable, use eg “sh” command

***********************************************
Regular Expression Symbols
●.    matches any character
lecture..    The word “lecture” followed by any 2 characters
●^    start of line
^The    A line starting with the word “The”
●$    end of line
end$    A line ending with the word “end”
●[ ]    one of the enclosed characters
lecture[123]  lecture1 lecture2 or lecture3 match this

“ls > outfile”
–runs “ls” and redirects all the output from “ls” to the file “outfile”
“ls | wc”
–runs “ls” and redirects all the output from “ls” to be input to “wc”

**********************************************    

          
安装卸载程序
●Install
–# rpm -i
●Update
–# rpm -u
●Query
–# rpm -q

          
Need to solve:
1. chmod 0740第一个bit数字状态代表setUID的什么状态.
answer: setUID 4, SetGID 2, Sticky 1

    Share:
    Back to Blog