草庐IT

linux-用户的权限

未知百分百 2023-06-17 原文
一、基本权限UGO
1、设置权限的两个方面
2、权限的三种类 对象
  • 属主:u(user)
  • 属组:g(group)
  • 其他人:o(other)
  • 特殊对象:所有人:a(all)(u+g+o)
3、权限的三种 类型(八进制)
  • 读:r=4
  • 写:w=2
  • 执行:x=1
4、 设置权限
4.1使用符号
chmod(change mode)命令:
可以修改 u g o 的  r-4   w-2  x-1
语法:
 chmod           u+r                 1.txt
    命令      对象加减权限      文件或目录
注意:这是在对文件授权;在对 文件夹授权时需要   -r
[root@localhost ~]# cd   /tmp/
[root@localhost tmp]#
//先进入到(tmp)临时目录中去
[root@localhost tmp]# touch file1
//创建文件file1
[root@localhost tmp]# ls -l
[root@localhost tmp]# ll file1
- rw-   r--    r--.        1       root      root        0                
 属主 属组 其他人   链接     属主      属组      大小
7月  27    15:14      file1
     创建时间          文件名
rwx:表示拥有所有权限
要求1:给file授予属主读的权限,没有写和执行
[root@localhost ~]# chmod u=r file1
[root@localhost ~]# ls -l file1
-r--r--r--. 1 root root 0 7月  27 15:57 file1
要求2:给file授予属组读、写和执行的权限
[root@localhost ~]# chmod g=rwx file1
[root@localhost ~]# ls -l file1
-r--rwxr--. 1 root root 0 7月  27 15:57 file1
要求3:给file授予其他用户没有读写和执行的权限
[root@localhost ~]# chmod o=  file1
[root@localhost ~]# ls -l file1
-r--rwx---. 1 root root 0 7月  27 15:57 file1
[root@localhost tmp]# ls -l -d /tmp/
drwxrwxrwt. 179 root root 16384 7月  27 16:10 /tmp/
用数字修改权限
1:执行      2:写       4:读
[root@localhost tmp]# chmod 777 /tmp/file1
[root@localhost tmp]# ls -l /tmp/file1
-rwxrwxrwx. 1 root root 0 7月  27 15:14 /tmp/file1
——————————————————————
chown命令(change owner)
可以修改用户和组
[root@localhost tmp]# chown  user01.hr /tmp/file1
                                                   用户     组
[root@localhost tmp]# ls -l /tmp/file1
-rwxrwxrwx. 1 user01 hr 0 7月  27 15:14 /tmp/file1
chogrep:只能修改组
注意:以上三种修改方式均可在文件中适用
但是在文件中的设置权限不会添加到子文件下的文件中
如需添加在命令中加     -r(递归)
案例:[root@localhost tmp]#  mkdir /temp/hr
mkdir: 无法创建目录"/temp/hr": 没有那个文件或目录
[root@localhost tmp]#  mkdir /tmp/hr
[root@localhost tmp]# ls -d /tmp/hr
/tmp/hr
[root@localhost tmp]# ls -d /tmp/hr -l
d rwx r-x r-x. 2 root root 6 7月  27 17:07 /tmp/hr
//查看修改前
[root@localhost tmp]# chmod 770 /temp/hr
//给r和g全部权限  给o 没有任何权限
[root@localhost tmp]# ls -l -d   /tmp/hr
//查看修改后
drwxrwx---. 2 root root 6 7月  27 17:07 /tmp/hr
二、ACL文件权限管理
特点:可以设置不同的用户,不同的基本权限(r,w,x)对象数量不同;
UGO:只能一个用户,一个组,或者其他人
语法:setfacl(设置文件访问控制列表)
setfacl  -m  u(user)/g(group)/o(other):hr:rwx /文件路径
            设置                     对象      :对象名:权限
root@localhost tmp]# touch /home/test
//创建文件
[root@localhost tmp]# ls /home
1  AAA  BBB  test  user01  user02  user03  user04  yps
[root@localhost tmp]# ls -l /home/test
-rw-r--r--. 1 root root 0 7月  27 20:17 /home/test
//查看文件
1、查看文件权限
[root@localhost tmp]# getfacl /home/test
getfacl: Removing leading '/' from absolute path names
# file: home/test
# owner: root
# group: root
user::rw-
group::r--
other::r--
2、设置用户权限
注意:设置之前一定要先创建用户
[root@localhost tmp]# useradd user01
[root@localhost tmp]# useradd user02
_________________________________________________
[root@localhost tmp]# setfacl  -m u:user01: rw /home/test
[root@localhost tmp]# setfacl  -m u:user02: - /home/test
[root@localhost tmp]# getfacl  /home/test
getfacl: Removing leading '/' from absolute path names
# file: home/test
# owner: root
# group: root
user::rw-
user:user01:rw-
user:user02:---
group::r--
mask::rw-
other::r--
3.删除
[root@localhost tmp]# setfacl -x u:user01 /home/test
//删除用户访问权限(注意:不用写权限(r,w,x))
[root@localhost tmp]# getfacl /home/test
getfacl: Removing leading '/' from absolute path names
# file: home/test
# owner: root
# group: root
user::rw-
user:user02:---
group::r--
mask::r--
other::r--
建立:-m   ;删除:-x  ;清除干净:-b   ;
三、特殊权限(了解)
例如:不小心删除了文件怎么办
1、特殊位 suid
功能:使调用文件的用户,临时具备属主能力
[root@localhost ~]# chmod u+s(suid) /home/test
[root@localhost ~]# ls  -l  /home/test
-rwsrw----+ 1 user01 hr 0 7月  27 20:17 /home/test
2、文件属性 chattr    -i(不可以被删除)
wghtsch - n1‘ getfacl /tmp/file1
wghtsch - n1‘ lsattr /tmp/file1
3、进程掩码 umask :掩码与权限相反
掩码0022+权限0755=0777
文件的默认权限为644:
目的:系统为例保护自己,在新建的文件上取消了执行权限
[root@localhost ~]# umask
0022
[root@localhost ~]# mkdir yangpanshaui
[root@localhost ~]# touch yangpanshauifile
[root@localhost ~]# ls -dl yangpanshaui  yangpanshauifile
drwxr-xr-x. 2 root root 6 7月  28 11:11 yangpanshaui
-rw-r--r--. 1 root root 0 7月  28 11:11 yangpanshauifile

有关linux-用户的权限的更多相关文章

  1. ruby-on-rails - 使用 rails 4 设计而不更新用户 - 2

    我将应用程序升级到Rails4,一切正常。我可以登录并转到我的编辑页面。也更新了观点。使用标准View时,用户会更新。但是当我添加例如字段:name时,它​​不会在表单中更新。使用devise3.1.1和gem'protected_attributes'我需要在设备或数据库上运行某种更新命令吗?我也搜索过这个地方,找到了许多不同的解决方案,但没有一个会更新我的用户字段。我没有添加任何自定义字段。 最佳答案 如果您想允许额外的参数,您可以在ApplicationController中使用beforefilter,因为Rails4将参数

  2. ruby-on-rails - 简单的 Ruby on Rails 问题——如何将评论附加到用户和文章? - 2

    我意识到这可能是一个非常基本的问题,但我现在已经花了几天时间回过头来解决这个问题,但出于某种原因,Google就是没有帮助我。(我认为部分问题在于我是一个初学者,我不知道该问什么......)我也看过O'Reilly的RubyCookbook和RailsAPI,但我仍然停留在这个问题上.我找到了一些关于多态关系的信息,但它似乎不是我需要的(尽管如果我错了请告诉我)。我正在尝试调整MichaelHartl'stutorial创建一个包含用户、文章和评论的博客应用程序(不使用脚手架)。我希望评论既属于用户又属于文章。我的主要问题是:我不知道如何将当前文章的ID放入评论Controller。

  3. ruby - RVM "ERROR: Unable to checkout branch ."单用户 - 2

    我在新的Debian6VirtualBoxVM上安装RVM时遇到问题。我已经安装了所有需要的包并使用下载了安装脚本(curl-shttps://rvm.beginrescueend.com/install/rvm)>rvm,但以单个用户身份运行时bashrvm我收到以下错误消息:ERROR:Unabletocheckoutbranch.安装在这里停止,并且(据我所知)没有安装RVM的任何文件。如果我以root身份运行脚本(对于多用户安装),我会收到另一条消息:Successfullycheckedoutbranch''安装程序继续并指示成功,但未添加.rvm目录,甚至在修改我的.bas

  4. ruby - rbenv 安装权限被拒绝 - 2

    大家好,我正在尝试设置一个开发环境,并且我一直在关注以下教程:Linktotutorial我做得不是很好,除了最基本的版本控制内容外,我对终端命令没有任何实际经验。我点击了第一个链接并尝试运行source~/.bash_profile我得到了错误;mkdir:/usr/local/rbenv/shims:权限被拒绝mkdir:/usr/local/rbenv/versions:权限被拒绝现在每次我加载终端时都会出现错误。bash_profile的内容;exportPATH=/usr/local/rbenv/bin:$PATHexportRBENV_ROOT=/usr/local/rbe

  5. ruby - 在没有基准或时间的情况下用 Ruby 测量用户时间或系统时间 - 2

    因为我现在正在做一些时间测量,我想知道是否可以在不使用Benchmark类或命令行实用程序time的情况下测量用户时间或系统时间。使用Time类只显示挂钟时间,而不显示系统和用户时间,但是我正在寻找具有相同灵active的解决方案,例如time=TimeUtility.now#somecodeuser,system,real=TimeUtility.now-time原因是我有点不喜欢Benchmark,因为它不能只返回数字(编辑:我错了-它可以。请参阅下面的答案。)。当然,我可以解析输出,但感觉不对。*NIX系统的time实用程序也应该可以解决我的问题,但我想知道是否已经在Ruby中实

  6. ruby-on-rails - 使用 javascript 更改数据方法不会更改 ajax 调用用户的什么方法? - 2

    我遇到了一个非常奇怪的问题,我很难解决。在我看来,我有一个与data-remote="true"和data-method="delete"的链接。当我单击该链接时,我可以看到对我的Rails服务器的DELETE请求。返回的JS代码会更改此链接的属性,其中包括href和data-method。再次单击此链接后,我的服务器收到了对新href的请求,但使用的是旧的data-method,即使我已将其从DELETE到POST(它仍然发送一个DELETE请求)。但是,如果我刷新页面,HTML与"new"HTML相同(随返回的JS发生变化),但它实际上发送了正确的请求类型。这就是这个问题令我困惑的

  7. ruby - HTTP 请求中的用户代理,Ruby - 2

    我是Ruby的新手。我试过查看在线文档,但没有找到任何有效的方法。我想在以下HTTP请求botget_response()和get()中包含一个用户代理。有人可以指出我正确的方向吗?#PreliminarycheckthatProggitisupcheck=Net::HTTP.get_response(URI.parse(proggit_url))ifcheck.code!="200"puts"ErrorcontactingProggit"returnend#Attempttogetthejsonresponse=Net::HTTP.get(URI.parse(proggit_url)

  8. ruby-on-rails - capybara poltergeist - 覆盖用户代理 - 2

    有人知道如何将capybarapoltergeist的用户代理覆盖到移动用户代理以进行测试吗?我发现了一些有关为seleniumwebdriver配置它的信息:http://blog.plataformatec.com.br/2011/03/configuring-user-agents-with-capybara-selenium-webdriver/这在capybara闹鬼中怎么可能? 最佳答案 请参阅poltergeistgithub页面上的链接:https://github.com/teampoltergeist/polte

  9. ruby-on-rails - 如何用不同的用户运行nginx主进程 - 2

    A/ctohttp://wiki.nginx.org/CoreModule#usermaster进程曾经以root用户运行,是否可以以不同的用户运行nginxmaster进程? 最佳答案 只需以非root身份运行init脚本(即/etc/init.d/nginxstart),就可以用不同的用户运行nginxmaster进程。如果这真的是你想要做的,你将需要确保日志和pid目录(通常是/var/log/nginx&/var/run/nginx.pid)对该用户是可写的,并且您所有的listen调用都是针对大于1024的端口(因为绑定(

  10. ruby-on-rails - 验证电子邮件地址是 Paypal 用户 - 2

    我想验证一个电子邮件地址是否是PayPal用户。是否有API调用来执行此操作?是否有执行此操作的ruby​​库?谢谢 最佳答案 GetVerifiedStatus来自PayPal'sAdaptiveAccounts平台会为您做这件事。PayPal没有任何codesamples或SDKs用于Ruby中的自适应帐户,但我确实找到了编写codeforGetVerifiedStatusinRuby的人.您需要更改该代码以检查他们拥有的帐户类型的唯一更改是更改if@xml['accountStatus']!=nilaccount_status

随机推荐