挂载iso文件:
/root/redhat.iso /mnt/cdrom iso9660 loop 0 0
showmount -e 192.168.0.254
mkdir /mnt/nfs
[参考]mount 192.168.0.254:/var/ftp/pub /mnt/nfs
vi /etc/fstab
192.168.0.254:/var/ftp/pub /mnt/nfs nfs defaults 0 0
mount -a
自动挂载
service autofs status [配置文件/etc/auto.master]
/misc/cd <== /dev/cdrom
1父目录:/misc
2子目录:cd
3设备/dev/cdrom
vi /etc/auto.master
1 /etc/子配置文件
vi /etc/子配置文件
2 3
修改了auto.master文件夹被修改,需要重启service autofs stop|start,不要使用restart
实现如下的自动挂载:
/d1/d2/d3/cd cdrom
/d1/d2/d3/nfs 192.168.0.254:/var/ftp/pub
/d1/d2/d3/cd|nfs目录都不用手工创建
修改/etc/auto.master
添加
/d1/d2/d3 /etc/abc.klt[相对路径法]
/- /etc/abc.klt[绝对路径法]
cp /etc/auto.misc /etc/abc.klt
vi /etc/abc.klt
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom[相对路径法]
nfs -fstype=nfs 192.168.0.254:/var/ftp/pub[相对路径法]
/home/cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom[绝对路径法]
/home/nfs -fstype=nfs 192.168.0.254:/var/ftp/pub[绝对路径法]
相对路径法的结果:如果/d1/d2/d3使用/home类似的目录,挂载成功后home里面的东西就没有了[如果/d1/d2/d3换成/,那结果是灾难性的]
auto.master文件里/net -hosts的作用:
vi /etc/auto.master
showmount -e 192.168.0.254
cd /net
cd 192.168.0.254
nfs共享,存在安全隐患,如果本机有目标机相同uid的用户,su本机用户,可以进入目标机相同uid的目录
usermod -u 2010 haha
【auto.master】
/- /etc/abc.klt
【abc.klt】
/home/haha -fstype=nfs 192.168.0.254:/home/guests/guest2020
su - haha
把远程当成home目录
nis:
ypcat -d notexample -h 192.168.0.254 passwd
getent passwd【可以看到本地帐号和nis帐号】
把自己的机器配置为客户端
system-config-authentication
user account database:NIS
NIS domain:notexample
NIS IP:192.168.0.254
authentication method:NIS Password
然后apply
getent passwd 查看nis用户的路径:
配置自动挂载服务:
auto.master
/- /etc/abc.klt
/etc/abc.klt
/nishome/nisuser2020 -fstype=nfs 192.168.0.254:/home/guests/guest2020
service auto.master restart
su - guest2020
grep -v "#" /etc/auto.master 显示没有注释的行
LDAP:
yum groupinstall directory-client
先完成ntp试验、先关闭防火墙、配置DNS
system-config-authentication
user account database:LDAP
LDAP search base DN:dc=example,dc=com
LDAP server:instructor.example.com[不能使用IP地址]
选择:use TLS to encrypt connections
download CA certificate:ftp://192.168.0.254/pub/example-ca.crt
authentication method:LDAP Password
然后apply
getent passwd ldapuser20查看ldap用户的路径:
配置自动挂载服务:
auto.master
/- /etc/abc.klt
/etc/abc.klt
/ldaphome/ldap20 -fstype=nfs 192.168.0.254:/home/guests/ldapuser20
service auto.master restart
su - ldapuser20
ssh -X 192.168.0.155【后面才可以打开图形界面,要不报错:
[root@server55 ~]# system-config-authentication
Unable to initialize graphical environment. Most likely cause of failure
is that the tool was not run using a graphical environment. Please either
start your graphical user interface or set your DISPLAY variable
】
vi /etc/sssd/sssd.conf【system-config-authentication的后台配置文件】(system security services daemon)
文件最后添加如下
enumerate = true
保存
service sssd restart
getent passwd就可以列出ldap用户了
SUID:所有者的权限(普通用户执行passwd,可以临时继承文件所有者的U权限)
作用在二进制的可执行文件上,不可以执行在脚本文件上。
[root@desktop118 home]# ll /usr/bin/passwd
-rwsr-xr-x. 1 root root 32680 Jan 29 2010 /usr/bin/passwd
chmod u-s /usr/bin/passwd(chmod 4755 /usr/bin/passwd)
-rwxr-xr-x. 1 root root 32680 Jan 29 2010 /usr/bin/passwd
/bin/vi 加了s权限后,其他用户就可以编写shadow了,很危险。
SGID:普通用户执行passwd,可以临时继承文件所有者的G权限
作用在二进制的可执行文件上,不可以执行在脚本文件上。
chmod u+s,g+s /bin/vi
chmod 6755 /bin/vi
chmod 6644 /bin/vi
SGID作用在dir上:在该目录下创建的子文件或文件夹都继承该文件夹的组属性。(团队工作应用场景)
mkdir d1
ll -d d1
useradd alice
groupadd sales
usermod -aG sales king
usermod -aG sales tom
usermod -aG sales alice
groupmems -l -g sales
chgrp sales d1
ll -d d1
chmod g+w d1
ll -d d1
su - king
su - tom
chmod g+s d1
ll -d d1
drwxrwsr-x. 3 root sales 4096 Apr 15 09:58 d1
cd d1
dir
> root
ll
cd ..
ll -d d1
su - king
su - tom
su king
chmod g=rwxs d1
sticky:目录里面可以建文件,修改别人的文件,但不可以删除别人的文件:
chmod o+t /home/d1
ll /tmp
SUID SGID sticky
4 2 1
chmod 7755 /home/d1
drwsr-sr-t. 3 root sales 4096 Apr 15 09:58 d1
root不可以修改,避免误操作
chattr +i f1
lsattr f1
chattr -i f1
lsattr f1
分区保护:mount -o ro /dev /mnt
mount -o rw,remount /dev/mnt
chattr +a f2 只可以加
echo jump >>f2
编辑提示不可以更新文件,因为编辑的时候判断不出来在那里添加。
acl:访问控制列表,先前的UGO(rwx)不够用,acl用于更复杂的权限控制
要设ACL,所在分区必须支持ACL,fat格式不支持acl
tune2fs -l /dev/sda1|grep option[操作系统默认安装的分区有acl功能]
setfacl -m u:king:0 f1
-rw-r--r--+ 1 root root 207 Apr 15 10:49 f1
[root@desktop118 sdb1]# setfacl -x u:king f1
[root@desktop118 sdb1]# getfacl f1
# file: f1
# owner: root
# group: root
user::rw-
group::r--
mask::r--
other::r--
清除acl(做错了重来)
[root@desktop118 sdb1]# setfacl -b f1
[root@desktop118 sdb1]# ll
total 24
-rw-r--r--. 1 root root 212 Apr 15 10:57 f1
setfacl -m u:wang:rwx file|directory【影响现有文件】
setfacl -m g:salesgroup:rw file| directory
setfacl -m d:u:wang:rx directory【影响新建文件】
1175 setfacl -m d:king:rw dir
1176 getfacl dir
1177 su - king
1178 ll
1179 cd dir
1180 ll
1181 >klt
1182 getfacl klt
1183 su king
1184 dir
1185 cd ..
1186 getfacl -R dir>dir1.acl
1187 setfacl -R -b dir
1188 getfacl dir
1189 dir
1190 setfacl --restore dir1.acl
1191 getfacl dir
1192 getfacl -R dir1
1193 getfacl -R dir
在/data/testdir里创建的新文件自动属于g1组,组g2的成员如:alice能对这些新文件有读写权限,
组g3的成员如:tom只能对新文件有读权限,其它用户(不属于g1,g2,g3)不能访问这个文件夹:
mkdir testdir
chgrp g1 testdir
chmod g+s testdir
setfacl -m d:g:g2:rw ../testdir
setfacl -m d:g:g3:r ../testdir
chmod 2750 testdir/
acl的权限的优先级小于用户权限,文件用户可以设置文件的acl权限给别人
umask 026(临时设置,如果写到.bash_profile中的话就可以永久生效)
umask u=rw,g=r,o=
umask + default per=dir 777
普通用户002,管理员用户022
默认的新建文件有执行权限是很危险的。
666
136
110110110 660
001011110 136
110100000 640
umask + default per=file666(先减,看结果是否有奇数,有就加一,偶数不变)
[root@desktop118 ~]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda2 1310720 93108 1217612 8% /
tmpfs 126587 5 126582 1% /dev/shm
/dev/sda1 128016 44 127972 1% /boot
/home/redhat6264.iso 0 0 0 - /mnt/iso
/dev/sdb1 50736 21 50715 1% /mnt/sdb1
Inodes代表可创建的最大文件数。有时空间没有增加,节点数耗尽,可能是节点数被耗尽导致。
空间是个资源,节点号也是资源
watch -n 1 'df -i /boot'
mv命令可以保住文件、目录的权限
tune2fs -l /dev/sda6可以看到inode的数量,在mkfs的时候可以指定inode的数量,mkfs后就没有办法修改inode的数量。
磁盘配额:
fstab里面的defaults不支持quota
fdisk /dev/sda5 挂载单独的分区到/home目录
vi /etc/fstab
/dev/sda5 /home/ ext4 usrquota,grpquota 0 0
mount -o remount /dev/sda5 /home
mount
/dev/sda5 on /home type ext4 (rw,usrquota,grpquota)
quotacheck -cug /home
【home是mv/cp来的,数据没有丢失,但操作系统记录的东西有些变化了。
1287 setenforce 0
1288 getenforce
1289 vi /etc/sysconfig/selinux
1290 getenforce
】
quotacheck -cug /home
ll aquota*
file aquota.*
quotaon /home
quotaon -p /home
group quota on /home (/dev/sda5) is on
user quota on /home (/dev/sda5) is on
edquota king[k为单位]
Disk quotas for user king (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/sda5 100000 80000 100000 117 400000 50000
su - king 【测试设置】
[king@desktop118 ~]$ dd if=/dev/zero of=~/quotafile bs=1M count=50
50+0 records in
50+0 records out
52428800 bytes (52 MB) copied, 0.176246 s, 297 MB/s
[king@desktop118 ~]$ dd if=/dev/zero of=~/quotafile bs=1M count=85
sda5: warning, user block quota exceeded.
85+0 records in
85+0 records out
89128960 bytes (89 MB) copied, 0.109546 s, 814 MB/s
[king@desktop118 ~]$ dd if=/dev/zero of=~/quotafile bs=1M count=120
sda5: warning, user block quota exceeded.
sda5: write failed, user block limit reached.
dd: writing `/home/king/quotafile': Disk quota exceeded
97+0 records in
96+0 records out
101646336 bytes (102 MB) copied, 0.265676 s, 383 MB/s
[king@desktop118 ~]$ cp /etc/hosts ff
cp: writing `ff': Disk quota exceeded
复制quota
edquota -p king tom
[root@desktop118 ~]# quota tom
Disk quotas for user tom (uid 502):
Filesystem blocks quota limit grace files quota limit grace
/dev/sda5 40 80000 100000 13 40000 50000
[root@desktop118 ~]# repquota /home
*** Report for user quotas on device /dev/sda5
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 3541348 0 0 244 0 0
king +- 100000 80000 100000 6days 117 40000 50000
tom -- 40 80000 100000 13 40000 50000
testuser -- 4 0 0 1 0 0
alice -- 68 0 0 17 0 0
#501 -- 32 0 0 8 0 0
#2023 -- 32 0 0 8 0 0
取消quota
[root@desktop118 home]# quotaoff /home
[root@desktop118 home]# quotaon -p /home
group quota on /home (/dev/sda5) is off
user quota on /home (/dev/sda5) is off
mount -o remount /dev/sda5 /home
/root/redhat.iso /mnt/cdrom iso9660 loop 0 0
showmount -e 192.168.0.254
mkdir /mnt/nfs
[参考]mount 192.168.0.254:/var/ftp/pub /mnt/nfs
vi /etc/fstab
192.168.0.254:/var/ftp/pub /mnt/nfs nfs defaults 0 0
mount -a
自动挂载
service autofs status [配置文件/etc/auto.master]
/misc/cd <== /dev/cdrom
1父目录:/misc
2子目录:cd
3设备/dev/cdrom
vi /etc/auto.master
1 /etc/子配置文件
vi /etc/子配置文件
2 3
修改了auto.master文件夹被修改,需要重启service autofs stop|start,不要使用restart
实现如下的自动挂载:
/d1/d2/d3/cd cdrom
/d1/d2/d3/nfs 192.168.0.254:/var/ftp/pub
/d1/d2/d3/cd|nfs目录都不用手工创建
修改/etc/auto.master
添加
/d1/d2/d3 /etc/abc.klt[相对路径法]
/- /etc/abc.klt[绝对路径法]
cp /etc/auto.misc /etc/abc.klt
vi /etc/abc.klt
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom[相对路径法]
nfs -fstype=nfs 192.168.0.254:/var/ftp/pub[相对路径法]
/home/cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom[绝对路径法]
/home/nfs -fstype=nfs 192.168.0.254:/var/ftp/pub[绝对路径法]
相对路径法的结果:如果/d1/d2/d3使用/home类似的目录,挂载成功后home里面的东西就没有了[如果/d1/d2/d3换成/,那结果是灾难性的]
auto.master文件里/net -hosts的作用:
vi /etc/auto.master
showmount -e 192.168.0.254
cd /net
cd 192.168.0.254
nfs共享,存在安全隐患,如果本机有目标机相同uid的用户,su本机用户,可以进入目标机相同uid的目录
usermod -u 2010 haha
【auto.master】
/- /etc/abc.klt
【abc.klt】
/home/haha -fstype=nfs 192.168.0.254:/home/guests/guest2020
su - haha
把远程当成home目录
nis:
ypcat -d notexample -h 192.168.0.254 passwd
getent passwd【可以看到本地帐号和nis帐号】
把自己的机器配置为客户端
system-config-authentication
user account database:NIS
NIS domain:notexample
NIS IP:192.168.0.254
authentication method:NIS Password
然后apply
getent passwd 查看nis用户的路径:
配置自动挂载服务:
auto.master
/- /etc/abc.klt
/etc/abc.klt
/nishome/nisuser2020 -fstype=nfs 192.168.0.254:/home/guests/guest2020
service auto.master restart
su - guest2020
grep -v "#" /etc/auto.master 显示没有注释的行
LDAP:
yum groupinstall directory-client
先完成ntp试验、先关闭防火墙、配置DNS
system-config-authentication
user account database:LDAP
LDAP search base DN:dc=example,dc=com
LDAP server:instructor.example.com[不能使用IP地址]
选择:use TLS to encrypt connections
download CA certificate:ftp://192.168.0.254/pub/example-ca.crt
authentication method:LDAP Password
然后apply
getent passwd ldapuser20查看ldap用户的路径:
配置自动挂载服务:
auto.master
/- /etc/abc.klt
/etc/abc.klt
/ldaphome/ldap20 -fstype=nfs 192.168.0.254:/home/guests/ldapuser20
service auto.master restart
su - ldapuser20
ssh -X 192.168.0.155【后面才可以打开图形界面,要不报错:
[root@server55 ~]# system-config-authentication
Unable to initialize graphical environment. Most likely cause of failure
is that the tool was not run using a graphical environment. Please either
start your graphical user interface or set your DISPLAY variable
】
vi /etc/sssd/sssd.conf【system-config-authentication的后台配置文件】(system security services daemon)
文件最后添加如下
enumerate = true
保存
service sssd restart
getent passwd就可以列出ldap用户了
SUID:所有者的权限(普通用户执行passwd,可以临时继承文件所有者的U权限)
作用在二进制的可执行文件上,不可以执行在脚本文件上。
[root@desktop118 home]# ll /usr/bin/passwd
-rwsr-xr-x. 1 root root 32680 Jan 29 2010 /usr/bin/passwd
chmod u-s /usr/bin/passwd(chmod 4755 /usr/bin/passwd)
-rwxr-xr-x. 1 root root 32680 Jan 29 2010 /usr/bin/passwd
/bin/vi 加了s权限后,其他用户就可以编写shadow了,很危险。
SGID:普通用户执行passwd,可以临时继承文件所有者的G权限
作用在二进制的可执行文件上,不可以执行在脚本文件上。
chmod u+s,g+s /bin/vi
chmod 6755 /bin/vi
chmod 6644 /bin/vi
SGID作用在dir上:在该目录下创建的子文件或文件夹都继承该文件夹的组属性。(团队工作应用场景)
mkdir d1
ll -d d1
useradd alice
groupadd sales
usermod -aG sales king
usermod -aG sales tom
usermod -aG sales alice
groupmems -l -g sales
chgrp sales d1
ll -d d1
chmod g+w d1
ll -d d1
su - king
su - tom
chmod g+s d1
ll -d d1
drwxrwsr-x. 3 root sales 4096 Apr 15 09:58 d1
cd d1
dir
> root
ll
cd ..
ll -d d1
su - king
su - tom
su king
chmod g=rwxs d1
sticky:目录里面可以建文件,修改别人的文件,但不可以删除别人的文件:
chmod o+t /home/d1
ll /tmp
SUID SGID sticky
4 2 1
chmod 7755 /home/d1
drwsr-sr-t. 3 root sales 4096 Apr 15 09:58 d1
root不可以修改,避免误操作
chattr +i f1
lsattr f1
chattr -i f1
lsattr f1
分区保护:mount -o ro /dev /mnt
mount -o rw,remount /dev/mnt
chattr +a f2 只可以加
echo jump >>f2
编辑提示不可以更新文件,因为编辑的时候判断不出来在那里添加。
acl:访问控制列表,先前的UGO(rwx)不够用,acl用于更复杂的权限控制
要设ACL,所在分区必须支持ACL,fat格式不支持acl
tune2fs -l /dev/sda1|grep option[操作系统默认安装的分区有acl功能]
setfacl -m u:king:0 f1
-rw-r--r--+ 1 root root 207 Apr 15 10:49 f1
[root@desktop118 sdb1]# setfacl -x u:king f1
[root@desktop118 sdb1]# getfacl f1
# file: f1
# owner: root
# group: root
user::rw-
group::r--
mask::r--
other::r--
清除acl(做错了重来)
[root@desktop118 sdb1]# setfacl -b f1
[root@desktop118 sdb1]# ll
total 24
-rw-r--r--. 1 root root 212 Apr 15 10:57 f1
setfacl -m u:wang:rwx file|directory【影响现有文件】
setfacl -m g:salesgroup:rw file| directory
setfacl -m d:u:wang:rx directory【影响新建文件】
1175 setfacl -m d:king:rw dir
1176 getfacl dir
1177 su - king
1178 ll
1179 cd dir
1180 ll
1181 >klt
1182 getfacl klt
1183 su king
1184 dir
1185 cd ..
1186 getfacl -R dir>dir1.acl
1187 setfacl -R -b dir
1188 getfacl dir
1189 dir
1190 setfacl --restore dir1.acl
1191 getfacl dir
1192 getfacl -R dir1
1193 getfacl -R dir
在/data/testdir里创建的新文件自动属于g1组,组g2的成员如:alice能对这些新文件有读写权限,
组g3的成员如:tom只能对新文件有读权限,其它用户(不属于g1,g2,g3)不能访问这个文件夹:
mkdir testdir
chgrp g1 testdir
chmod g+s testdir
setfacl -m d:g:g2:rw ../testdir
setfacl -m d:g:g3:r ../testdir
chmod 2750 testdir/
acl的权限的优先级小于用户权限,文件用户可以设置文件的acl权限给别人
umask 026(临时设置,如果写到.bash_profile中的话就可以永久生效)
umask u=rw,g=r,o=
umask + default per=dir 777
普通用户002,管理员用户022
默认的新建文件有执行权限是很危险的。
666
136
110110110 660
001011110 136
110100000 640
umask + default per=file666(先减,看结果是否有奇数,有就加一,偶数不变)
[root@desktop118 ~]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda2 1310720 93108 1217612 8% /
tmpfs 126587 5 126582 1% /dev/shm
/dev/sda1 128016 44 127972 1% /boot
/home/redhat6264.iso 0 0 0 - /mnt/iso
/dev/sdb1 50736 21 50715 1% /mnt/sdb1
Inodes代表可创建的最大文件数。有时空间没有增加,节点数耗尽,可能是节点数被耗尽导致。
空间是个资源,节点号也是资源
watch -n 1 'df -i /boot'
mv命令可以保住文件、目录的权限
tune2fs -l /dev/sda6可以看到inode的数量,在mkfs的时候可以指定inode的数量,mkfs后就没有办法修改inode的数量。
磁盘配额:
fstab里面的defaults不支持quota
fdisk /dev/sda5 挂载单独的分区到/home目录
vi /etc/fstab
/dev/sda5 /home/ ext4 usrquota,grpquota 0 0
mount -o remount /dev/sda5 /home
mount
/dev/sda5 on /home type ext4 (rw,usrquota,grpquota)
quotacheck -cug /home
【home是mv/cp来的,数据没有丢失,但操作系统记录的东西有些变化了。
1287 setenforce 0
1288 getenforce
1289 vi /etc/sysconfig/selinux
1290 getenforce
】
quotacheck -cug /home
ll aquota*
file aquota.*
quotaon /home
quotaon -p /home
group quota on /home (/dev/sda5) is on
user quota on /home (/dev/sda5) is on
edquota king[k为单位]
Disk quotas for user king (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/sda5 100000 80000 100000 117 400000 50000
su - king 【测试设置】
[king@desktop118 ~]$ dd if=/dev/zero of=~/quotafile bs=1M count=50
50+0 records in
50+0 records out
52428800 bytes (52 MB) copied, 0.176246 s, 297 MB/s
[king@desktop118 ~]$ dd if=/dev/zero of=~/quotafile bs=1M count=85
sda5: warning, user block quota exceeded.
85+0 records in
85+0 records out
89128960 bytes (89 MB) copied, 0.109546 s, 814 MB/s
[king@desktop118 ~]$ dd if=/dev/zero of=~/quotafile bs=1M count=120
sda5: warning, user block quota exceeded.
sda5: write failed, user block limit reached.
dd: writing `/home/king/quotafile': Disk quota exceeded
97+0 records in
96+0 records out
101646336 bytes (102 MB) copied, 0.265676 s, 383 MB/s
[king@desktop118 ~]$ cp /etc/hosts ff
cp: writing `ff': Disk quota exceeded
复制quota
edquota -p king tom
[root@desktop118 ~]# quota tom
Disk quotas for user tom (uid 502):
Filesystem blocks quota limit grace files quota limit grace
/dev/sda5 40 80000 100000 13 40000 50000
[root@desktop118 ~]# repquota /home
*** Report for user quotas on device /dev/sda5
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 3541348 0 0 244 0 0
king +- 100000 80000 100000 6days 117 40000 50000
tom -- 40 80000 100000 13 40000 50000
testuser -- 4 0 0 1 0 0
alice -- 68 0 0 17 0 0
#501 -- 32 0 0 8 0 0
#2023 -- 32 0 0 8 0 0
取消quota
[root@desktop118 home]# quotaoff /home
[root@desktop118 home]# quotaon -p /home
group quota on /home (/dev/sda5) is off
user quota on /home (/dev/sda5) is off
mount -o remount /dev/sda5 /home