ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

RHCE-6

2021-12-23 21:01:07  阅读:204  来源: 互联网

标签:RHCE upload server nfs 172.24 jerry root


架设一台NFS服务器,并按照以下要求配置

1、开放/nfs/shared目录,供所有用户查询资料;

服务器端(172.24.8.130):

创建共享目录/nfs/shared,在配置文件(/etc/exports)中给只读权限,重启服务,并重新记载内容

[root@server-1 ~]# mkdir -p /nfs/shared/ #创建共享目录
[root@server-1 ~]# vim /etc/exports
/nfs/shared *(ro)

[root@server-1 ~]# systemctl restart nfs-server #重启服务
[root@server-1 ~]# exportfs -r         #重新读取配置内容

客户端(172.24.8.133):

将服务端的共享目录/nfs/shared挂载到客户端的/mnt目录下

[root@client_1 ~]# showmount -e 172.24.8.130
Export list for 172.24.8.130:
/nfs/shared *
[root@client_1 ~]# mount 172.24.8.130:/nfs /mnt
[root@client_1 ~]# ll /mnt
total 0
drwxr-xr-x. 2 root root 6 Dec 23 17:35 shared

2、开放/nfs/upload目录,该目录为172.24.8.0/24网段的主机的数据上传目录,并将所有该网段主机上传文件的所属者和所属组映射为nfs-upload,其UID和GID为2001;

服务器端(172.24.8.130):

创建开放目录/ns/upload并给upload目录增加o+w的权限,创建用户nfs-upload,指定其UID为2001,GID默认也为2001,修改配置文件/etc/exports 重启服务,并重新加载配置文件

[root@server-1 ~]# mkdir -p /nfs/upload   #创建目录
[root@server-1 ~]# chmod o+w /nfs/upload/ #给upload目录权限
[root@server-1 ~]# tree /nfs
/nfs
├── shared
└── upload

2 directories, 0 files

[root@server-1 ~]# useradd nfs-upload -u 2001
[root@server-1 ~]# id nfs-upload
uid=2001(nfs-upload) gid=2001(nfs-upload) groups=2001(nfs-upload)
[root@server-1 ~]# vim /etc/exports
/nfs/shared *(ro)
/nfs/upload 172.24.8.0/24(rw,all_squash,anonuid=2001,anongid=2001))

[root@server-1 ~]# systemctl restart nfs-server
[root@server-1 ~]# exportfs -r

客户端(172.24.8.133):

[xiaohei@client_1 upload]$ vim file2
[xiaohei@client_1 upload]$ ll
total 4
-rw-rw-r--. 1 2001 2001 9 Dec 23 19:48 file2

 服务器端(172.24.8.130):

[root@server-1 ~]# ll /nfs/upload/
total 4
-rw-rw-r--. 1 nfs-upload nfs-upload 9 Dec 23 19:48 file2

[root@server-1 ~]# ll -n /nfs/upload/
total 4
-rw-rw-r--. 1 2001 2001 9 Dec 23 19:48 file2

3、将/home/tom(该目录为uid=1111,gid=1111的tom用户的家目录)目录仅共享给172.24.8.129这台主机上的jerry用户,jerry对该目录具有访问、新建和删除文件的权限。

  服务器端(172.24.8.130):

创建tom用户指定其uid为1111,gid为默认的1111,编辑配置文件/etc/esports 重启服务并重新加载配置文件

[root@server-1 ~]# useradd tom -u 1111
[root@server-1 ~]# vim /etc/exports

/nfs/shared *(ro)
/nfs/upload 172.24.8.*(rw,all_squash,anonuid=2001,anongid=2001)
/home/tom  172.24.8.129/24(rw)

[root@server-1 ~]# systemctl restart nfs-server
[root@server-1 ~]# exportfs -r

客户端(172.24.8.129):

先给客户端的一个网卡添加新的ip地址172.24.8.129,登陆到174.24.8.129

[root@client_1 ~]# nmcli connection modify ens256 +ipv4.addresses 172.24.8.129/24
[root@client_1 ~]# nmcli connection up ens256
ssh root@172.24.8.129
Warning: Permanently added '172.24.8.129' (RSA) to the list of known hosts.
root@172.24.8.129's password:
Last failed login: Thu Dec 23 20:23:04 CST 2021 from 172.24.8.1 on ssh:notty
There were 2 failed login attempts since the last successful login.
Last login: Thu Dec 23 19:58:58 2021

然后将服务器端的/home/tom文件挂载到客户端的/tom,创建用户jerry,指定其uid为1111,gid默认为1111,切换到jerry用户进行测试,再切换到xiaoming用户进行测试

[root@client_1 ~]# mkdir /tom     #创建/tom目录
[root@client_1 ~]# mount 172.24.8.130:/home/tom /tom  #挂载
[root@client_1 ~]# useradd jerry -u 1111   #添加用户jerry指定uid为1111
[root@client_1 ~]# echo 123 |passwd --stdin jerry  #给jerry用户设置密码
Changing password for user jerry.
passwd: all authentication tokens updated successfully.
[root@client_1 ~]# su - jerry    #切换到jerry用户
[jerry@client_1 ~]$ cd /tom            
[jerry@client_1 tom]$ touch file      #创建文件
[jerry@client_1 tom]$ ll
total 0
-rw-rw-r--. 1 jerry jerry 0 Dec 23 20:42 file
[jerry@client_1 tom]$ su - xiaoming     #切换到xiaoming用户
Password:
[xiaoming@client_1 ~]$ cd /tom
-bash: cd: /tom: Permission denied      #权限拒绝

测试结果:jerry用户有对应的权限,而其他用户没有权限

标签:RHCE,upload,server,nfs,172.24,jerry,root
来源: https://blog.csdn.net/weixin_45188948/article/details/122112894

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有