Chinaunix首页 | 论坛 | 博客
  • 博客访问: 713352
  • 博文数量: 235
  • 博客积分: 4309
  • 博客等级: 中校
  • 技术积分: 2325
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-17 11:25
个人简介

If you don\\\\\\\\\\\\\\\'t wanna do it, you find an EXCUSE; if you do, you\\\\\\\\\\\\\\\'ll find a WAY :-)

文章分类

全部博文(235)

文章存档

2014年(3)

2013年(2)

2012年(31)

2011年(199)

分类: LINUX

2011-02-17 18:28:49

一:用户和组配置文件
1.【User and Group ID Numbers】:


1.1.『passwd』
[root@rhel5 ~]#cat /etc/passwd  →→依次是:用户名、密码、UID、GID、fullname、主目录的路径、登录后第一个执行的process。

user1:x:500:500:user1:/home/use1:/bin/bash
user2:x:501:501::user1:/home/use2:/bin/bash
~

~:q

1.2.『shadow』
[root@rhel5 ~]#less /etc/shadow  →→ 查看使用者的密码, 密码是 UserID和Password 进行MD-5hash 加密后的结果。 
user1:$1$vo89pI5Y$v7tgazFYmDfeWbvfR/TlE1:12942:0:99999:7:::  →→ " $ "表示已经设置密码。 
user2:!!:12942:0:99999:7:::      →→ " !! "表示没有设置密码。 
 ——————————————————————————————————————
1.3.『group』   
[root@rhel5 ~]#less /etc/group  →→  查看群组资讯

root:x:0:root
user1:x:500:
user2:x:501:

~:q
1.4.『gshadow』
[root@rhel5 ~]#less /etc/gshadow →→  查看群组密码

root:::root

~:q

——————————————————————————————————————

 

二:管理文件权限

1.【Linux File Permissions】: (文件权限)


1.1.permission Types
r           -permission to read a file or list a directory's contents
w          -permission to write to a file or create and remove files from a directory
x           -permission to execute a program or change into a directory and do a long listing of the directory
-            -no permission (in place of the r,w, or x)

——————————————————————————————————————

1.1.2 Default Permissions

Access levels
u        user
g        group
o        other


档案文件的默认权限是:666
r w  x   r  w  x r  w x
|____|   |____| |____|
    u         g         o
Owner Group Other
4 2 0     4 2 0    4 2 0

目录的默认权限是:777
r  w x    r  w  x   r  w x
|____|    |____|   |____|
    u          g           o
Owner Group  Other
4 2 1     4 2 1    4 2 1


[root@rhel5 ~]#umask   →→  umask(设置文件权限掩码) 
0002  →→Non-privileged users umask   预设为:002

[root@localhost~]#umask  →→ Root's umask 预设为:022 
0022

——————————————————————————————————————
1.1.3 文件权限产生的全过程
                         u         g         o
                      ____   ____    ____
                     |        |  |        |  |        | 
File        666 r  w  - r  w  - r  w  -
umask   002 -   -   - -   -   - -  w  -
________________________________________
               664 r  w  - r  w  - r   -  -
(TIPS:以上为普通用户文件的权限)

                          u        g       o
                       ____  ____  ____
                      |        | |       |  |        | 
File        666 r  w  - r  w  - r  w  -
umask   022 -   -   - -  w  - -  w  -
________________________________________
              644 r  w  - r  -  - r   -  -
(TIPS:以上为Root 用户文件的权限)

——————————————————————————————————————


1.1.4. umask

[root@rhel5 ~]#umask 033  →→ 设定 umask 值

[root@rhel5 ~]# umask →→ 查看帐号umask 
0002
[root@rhel5 ~]# vi /etc/bashrc →→ 查看umask 
If [" id -gn " = " `id -un' " -a `id -u` -gt 99]; then →→ "gn"(group name) "un"(user name) 
umask 002 →→ 用户名称与群组名称一致时执行
else
umask 022
fi
[root@rhel5 ~]# vi /etc/passwd →→ 修改群组名称500 改为:501 
User1:x:500:501:,NY:/home/user1:/bin/bash
[root@rhel5 ~]# umask →→ umask 值变为:0022 
0022

——————————————————————————————————————


1.3.Access modes
r          read →→ File(cat) Directory(ls -l) 
w        write →→ File(vi, gedit) Directory(mv, touch, rm) 
x         execute →→ File(Shell script, executable) Directory(cd) 
Root? → (N) → uid: file's uid → (N) → gid:file's gid → (N) Other(r w x)
    (Y)↓                          (Y)↓                           (Y)↓
Access the file     User r w x                group r w x

——————————————————————————————————————

1.4.Examining Permissions

[root@rhel5 ~]#ls -ld /tmp        →→ 列出当前目录的详细内容 
[root@rhel5 ~]#ls -l /tmp/dir1  →→ 列出目录内档案的详细内容

——————————————————————————————————————


1.5. 【chmod】 →→ Changing Permissions

1.5.1.Symbolic Method
Syntax:chmod  mode file

mode选项如下:
Who operator permission
u(owner) +(add) r(read)
g(group) -(remove) w(write)
o(other) =(assign) x(execute)
a(all,包裹以上三组)

[root@rhel5 ~]#chmod go+w doc  →→ 赋予group 和 other write权限 到文件doc 
[root@rhel5 ~]#chmod  -R ugo -r doc  →→ 去除owner、group和other的 read权限 包裹doc极其子文件," -R " 表示同样应用到子文件。 

——————————————————————————————————————

15.2.Numeric Method

4          -for read
2          -for write
1          -for execute
0          -for no permission

r  w x     r  w x  r   w  x
|____|     |____|  |____|
    u           g          o
Max Permission 7 7 7(4 + 2 + 1)

[root@rhel5 ~]#chmod -R 754 doc  →→ 设置 rwx r-x r-- 754  权限到doc,包裹其子目录。
——————————————————————————————————————


2.【设定特殊权限】:


2.1.『SUID』
[root@rhel5 ~]#chmod u+s file1  →→ 加入  suid(4)   的特殊权限 ,作用:以档案拥有者的身份执行。


[root@rhel5 ~]#ping 192.168.0.1 -c4  →→  ping 4次
[root@rhel5 ~]#ls -l /bin/ping  →→ " s " 表示拥有特殊权限 "s" 
-rwsr-xr-x 1   root root   35108  Jun  18  2009 /bin/ping

[root@rhel5 ~]#chmod u-s /bin/ping  →→  去除Ping指令的 特殊权限 " s "

[root@rhel5 ~]#ls -l /bin/ping  →→  目前已经没有特殊权限 "s" 
-rwxr-xr-x 1   root root   35108  Jun  18  2009 /bin/ping

[root@rhel5 ~]#ping 192.168.0.1 -c4  →→  ping 4次
ping: icmp open socket: Operation not permitted(有权限执行 ping指令, 但是没有控制icmp socket  的权限。)

2.2.『SGID』
[root@rhel5 ~]#chmod g+s file2  →→ 加入  sgid(2)  的特殊权限 ,作用:以档案群组成员的身份执行。

2.3『STICKY』
[root@rhel5 ~]#chmod o+t file3  →→ 加入 sticky(1)  的特殊权限 ,作用:只有Owner和Root 可以删除此特殊权限的文件。

Example:
[root@rhel5 ~]#chmod 2755 file2  →→ 加入  sgid(2)  的特殊权限 
[root@rhel5 ~]#chmod 7755 file3  →→ 加入  suid(4)+sgid(2)+sticky(1) = 7  的特殊权限

[root@rhel5 ~]# chmod 777 /temp/user1.txt →→ 修改权限
[root@rhel5 ~]# chmod 3771 /temp/user1.txt →→ (SGID2 + Sticky1)=3 修改权限 

[root@rhel5 ~]#ls -ld /tmp  →→ 列出当前目录的详细内容 
drwxrwxrwt 17 root  root 4096 Jul 2 18:22  tmp →→ " t " sticky的特殊权限, 用以避免其他人误删。


——————————————————————————————————————


三:用户管理

1.【Changing Your Identity】:
『useradd、passwd、su 』

[root@rhel5 ~]#passwd  →→ 更改用户口令 
[root@rhel5 ~]#passwd user2  →→ 更改 其他 用户口令

[root@rhel5 ~]#useradd testuser  →→ 添加新用户 
[root@rhel5 ~]#passwd --status testuser   →→ 查看用户密码状态 
[root@rhel5 ~]#passwd -S testuser    →→查看用户密码状态

1.1 Su

Su [-] [user]
→→ " - " 会开启一个Login Shell , 这就是与No Login Shell 的区别。
Su [-] [user] -c command
[root@rhel5 ~]# su user1 -c 'echo $HOME' →→ 使用某个帐号执行一条指令

[root@rhel5 ~]#su testuser  →→ 切换用户 
[root@rhel5 ~]#su - testuser  →→ 不仅切换用户 而且切换使用的环境变量  
[root@rhel5 ~]#su  →→ 切换到root  
[root@rhel5 ~]#su -  →→ 切换到root 并且切换使用的环境变量  

[root@rhel5 ~]#whoami  →→  显示当前用户 
[root@rhel5 ~]#groups  →→ 显示目前用户属于哪个群组  
[root@rhel5 ~]#id   →→ 显示目前用户属于哪个群组 并且显示所属群组 ID  userID、groupID

[root@rhel5 ~]#users  →→  显示哪些用户登录到这台Linux系统 
[root@rhel5 ~]#who  →→ 显示哪些用户登录到这台Linux系统,  信息比较详细。
[root@rhel5 ~]#w  →→显示哪些用户登录到这台Linux系统,    信息最详细。 

[root@rhel5 ~]#last   →→ 查看用户登录、重启的  历史信息记录

 

2.【Access Control Lists】: (ACLs)
[root@rhel5 ~]# vi /etc/fstab
LABEL=/ / ext3 defaults,acl 1 1→→ 系统挂载目录时启用ACL 机制
[root@rhel5 ~]# mount -o remount / →→ 重新挂载根目录

3.【getfacl 】:
[root@rhel5 ~]# getfacl /project1 →→ 查看权限设定
getfacl : Removing leading '/' from absolute path names
#file: project1
#owner: user1
#group: projetc1
user:: rwx
group::rwx
other::--x


3.1【setfacl 】:
[root@rhel5 ~]# setfacl -m u:user2:r-x /project1
[root@rhel5 ~]# getfacl /project1
getfacl : Removing leading '/' from absolute path names
#file: project1
#owner: user1
#group: projetc1
user:: rwx
user:user2:r-x
group::rwx
mask::rwx
other::- -x

——————————————————————————————————————

4.【删除、修改用户】:
[root@rhel5 ~]# id user6 →→ 查看用户基本资料
Uid=505(user6) GID=505(user6) groups=505(user6)


[root@rhel5 ~]# cat /etc/passwd →→  查看用户详细资料
[root@rhel5 ~]# usermod -d /home/user-6 user6→→ 修改用户Home 路径, 但不会建立目录我们
需要手动建立目录


【File Ownership】:
[root@rhel5 ~]# mkdir /home/user-6
[root@rhel5 ~]# chown user6.user6 /home/user-6/ →→  变更目录的Owner 与Group 
[root@rhel5 ~]# chown user2:user2 /tmp/dir1 →→ 修改文件UID 和GID。

——————————————————————————————————————


4.1.【usermod】:
[root@rhel5 ~]# usermod -G user6 tom→→ 将tom 用户添加到其他groups user6(群组)

[root@rhel5 ~]# usermod -g user6 tom→→ 变更tom用户的group为 user6(群组)


[root@rhel5 ~]# usermod -L user6 →→  锁定某个帐号
[root@rhel5 ~]# usermod -U user6 →→  解除帐号锁定


[root@rhel5 ~]# userdel -r user6→→  删除用户帐号

——————————————————————————————————————


4.2.【Password Aging Policies】: (预设密码不会过期)
[root@rhel5 ~]# less /etc/shadow →→   " $1$ "(已设密码) " !! "(没有密码)" ! "(帐号被锁定) 
User6:$1$cgWXfGhy$K8yl4IqmmnjB9QeNPdjtF1:12985:1:7:7:3:13016

~

~:q

——————————————————————————————————————
4.2.1 chage →→  change user password expiry information

[root@rhel5 ~]# chage -l user6→→ show account aging information

Minimum: 0 →→   帐号使用多久才可以修改密码
Maximum: 99999 →→   密码最长使用期限
Warning: 7 →→   密码到期前几天警告讯息
Inactive: -1 →→  密码到期多久后没有修改密码就锁定帐号
Last Change: Jul 21,2009
Password Expires: Never
Password Inactive: Never
Account Expires: Never

~

~:q

——————————————————————————————————————
[root@rhel5 ~]# chage -d 2009-09-22 user 6 /* 修改用户变更密码的日期YYYY-MM-DD */
[root@rhel5 ~]# chage -m 1 user6 /* 修改帐号使用1 天后才可以修改密码*/
[root@rhel5 ~]# chage -M 7 user6 /* 修改密码最长使用期限7 天*/
[root@rhel5 ~]# chage -I 3 user6 /* 密码过期3 天后仍没有修改密码就锁定帐号*/
[root@rhel5 ~]# chage -E 2009-10-01 user6 /* 修改密码过期时间*/

——————————————————————————————————————

 

4.3.【User Policy Considerations】:
4.3.1 passwd
[root@rhel5 ~]# less /etc/passwd /*用户信息记录文件
root:x:0:0:root:/root:/bin/bash
...................../*依次是:用户名、是否有密码、UID、GID、finger information、主目录的路径、登录后
第一个执行的process。
user1:x:500:500:user1:/home/use1:/bin/bash →→ 1-499 的UID 保留给系统服务
user2:x:501:501::user1:/home/use2:/bin/bash
如果将user2 的" x " 改成空白:wq 退出;登录user2 则不需要输入密码了!

~

~:q

——————————————————————————————————————

4.3.2. finger
[root@rhel5 ~]# finger user1 →→ 查看user1 的用户资料
[root@rhel5 ~]# chfn -o NY user1 →→ 变更用户finger Information " -o "office NY(值)
Changing finger information for user1.
Finger information changed.
[root@rhel5 ~]# less /etc/passwd →→ 
............................
User1:x:500:500:,NY...........
............................


[root@rhel5 ~]# less /etc/passwd →→ 
...........................
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin (用户只能从FTP 登录)
[root@rhel5 ~]# ftp 192.168.0.144 →→ 首先建立与FTP 的连接
Connected to 192.168.0.144.
220 (vsFTPd 2.0.1)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.0.144:root):ftp →→ 输入登录名
331 Please specify the password.
Password: →→ 输入登录密码
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>


[root@rhel5 ~]# less /etc/passwd →→ 
...........................
mailuser x:507:507::/home/mailuser:/bin/false (用户只能收发邮件而不能登陆系统)
——————————————————————————————————————


4.3.3.【Adding a New User Account】:
新增用户后系统会编辑: /etc/passwd, /etc/shadow, /etc/group
建立:Home directory 并变更权限
[root@rhel5 ~]# useradd user3 →→ 新增用户
[root@rhel5 ~]# passwd user3 →→ 变更用户口令


4.3.4.【使用newusers 指令建立大量帐号】:
[root@rhel5 ~]# vi newuser →→ 首先新增一个档案存放用户资料
user4 user4:504:504::/home/user4:/bin/bash
user5 user5:505:505::/home/user5:/bin/bash
user6 user6:506:506::/home/user6/bin/bash
→→ 登陆名、密码、UID、Private group GID、fullname(fingerInformation)、Home 路径、登陆后第一个
要执行的Process。
~

~:wq

[root@rhel5 ~]#

newusers newuser →→ newusers 指令一次添加多个帐号。

——————————————————————————————————————


4.3.5.【User Private Groups】:一个新用户建立的档案都属于自身的Private group
权限为:700 rwx --- ---
[root@rhel5 ~]# cat /etc/group →→ group 名称、需要密码登录、GID、拥有哪些成员
User5:x:504:user5


4.3.6【Group Administration】:
[root@rhel5 ~]# groupadd →→ 添加群组
[root@rhel5 ~]# groupmod -n group2 group1→→ " -n " 重命名"group2"(new name) "group2"(old
name)
[root@rhel5 ~]# groupdel group2 →→ 删除群组


4.3.7【Login Shell Scripts】: (用户登录后会执行哪些Scripts)
/etc/profile → /etc/profile.d/*.sh → ~/.bash_profile → ~/.bashrc → /etc/bashrc
[root@rhel5 ~]# cat /etc/profile →→ 
[root@rhel5 ~]# cat ~/.bash_profile →→ 
[root@rhel5 ~]# cat ~/.bashrc →→


4.3.8【Non Login Shell Scripts】:
~/.bashrc → /etc/bashrc → /etc/profile.d/*.sh
——————————————————————————————————————


5.【Network Users】:
User Login → Check local accounts and passwords(/etc/passwd, /etc/shadow)→(非本地用户发送到服
务器进行验证) NIS LDAP →(验证成功) Network User

NIS 服务器负责区域内(Domain)用户登录的验证工作。
Account Information:UID number, Default Shell, Home Directory, Group Memberships ...
Authentication: a way to tell that the password provided on login for an account is correct.


6.【使用网络主机验证】:
[root@rhel5 ~]# less /etc/nsswitch.conf
......................................
passwd: files nis →→ files(查看本地文件) 
shadow: files nis →→ 通过NIS 服务器验证
group: files nis
..........................................


7.【Authentication Configuration】:
[root@rhel5 ~]# system-config-authentication →→ 图形界面管理验证配置工具
[root@rhel5 ~]# authconfig-tui →→ 文字界面管理验证配置工具


 

7.1【使用远端X Server】:
[root@rhel5 ~]# ssh -Y 192.168.0.144
root@192.168.0.144's password:
Last login: Thu Oct 20 16:39:50 2009 from localhost.domain.com
[root@rhel5 ~]# xterm

——————————————————————————————————————

 

8.【LDAP】:

DN: →→ CN=user1,OU=document,DC=rhel5,DC=com

rhel5.com →→ 由于有" . "所以要分隔开为 →→ DC=rhel5,DC=com


[root@rhel5 ~]# rpm -qa | grep ldap →→ 确认已安装openldap 和nss-ldap 套件。
openldap-2.2.13-2
nss_ldap-226-1
php-ldap-4.3.9-3.1
[root@rhel5 ~]# less /etc/ldap.conf →→ 
[root@rhel5 ~]# cat /etc/openldap/ldap.conf
[root@rhel5 ~]# less /etc/nsswitch.conf
......................................
passwd: files nis →→ files(查看本地文件) 
shadow: files nis →→ 通过NIS 服务器验证
group: files nis
..........................................
[root@rhel5 ~]# less /etc/pam.d/system-auth
[root@rhel5 ~]# authconfig-tui →→ 文字界面管理验证配置工具
Authentication Configuration
User Information Authentication
[]Cache Information    [*]Use MD5 Passwords
[]Use Hesiod                [*]Use Shadow Passwords
[*]Use LDAP                  [*]Use LDAP Authentication
[]Use NIS                       [ ]Use Kerberos
[]Use Winbind              [ ]Use SMB Authentication
[]Use Winbind Authentication
Cancel Next
→→ 选择LDAP
LDAP Settings
[*]Use TLS /*TLS 加密技术
Server:192.168.0.144___________________ →→ IP 
Base DN:dc=example,dc=com____________ →→ DN
Back Ok
[root@rhel5 ~]# less /etc/ldap.conf →→

host  192.168.0.144

ssl start_tls

~

~:q
[root@rhel5 ~]# cat /etc/openldap/ldap.conf

HOST 192.168.0.144

BASE dc=rhel5,dc=com

~

~:q
[root@rhel5 ~]# less /etc/nsswitch.conf
......................................
passwd: files ldap →→ files(查看本地文件) 
shadow: files ldap →→ 通过LDAP 服务器验证
group: files ldap
..........................................
[root@rhel5 ~]# less /etc/pam.d/system-auth →→ 此档案配置了将密码转送到LDAP 做验证
.............................................
auth sufficient /lib/security/$ISA/pam_ldap.so use_first_pass
account [default=bad success=ok user_unknown=ignore] /lib/security/$ISA/pam_ldap.so
password sufficient /lib/security/$ISA/pam_ldap.so use_authtok
session optional /lib/security/$ISA/pam_ldap.so
.............................................


#####################################################################
END TIPS:

split( uptime who chsh chfn finger last )

1.拆分
[root@localhost ~]# split -b 4m myfile.img myfileSp→→  注:分拆为大小为4M的文件;
[root@localhost ~]# ls -lh myfileSp* →→ 注:列出分拆文件,我们看到有两个文件;
-rw-r--r-- 1 root root 4.0M 04-27 20:37 myfileSpaa
-rw-r--r-- 1 root root 3.9M 04-27 20:37 myfileSpab

2.合并
[root@localhost ~]# cat myfileSp* > newmyfile.img→→  注:我们尝试合并文件到一个新文件中;
[root@localhost ~]# ls -lh newmyfile.img
-rw-r--r-- 1 root root 7.9M 04-27 20:38 newmyfile.img
3.验证完整性

[root@localhost ~]# md5sum newmyfile.img myfile.img
7eb24d865a14fa3227633816800522c1 myfile.img
7eb24d865a14fa3227633816800522c1 newmyfile.img

→→ 注:我们对比合并后文件和原文件的MD5值,如果M55值相同,就是完整的;
#####################################################################

 


——————————————————————————————————————


 

——————————————————————————————————————

阅读(615) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~