【问题标题】:Permissions issue on Amazon Ubuntu InstanceAmazon Ubuntu 实例上的权限问题
【发布时间】:2015-04-05 16:26:43
【问题描述】:

我正在尝试在我的实例上获得我的 ubuntu 适当权限,以便我可以运行 rails 服务器。但是,当我更改权限并尝试授予我的 ubuntu 用户 sudo 权限时,它拒绝访问 html 文件夹。我不知道可能是什么问题,因为我尝试将其添加为 sudo 用户,重新启动服务器,但它仍然失败。唯一可行的是将权限更改为我不想要的 777。我不知道为什么 ubuntu 用户权限会以他们的方式行事并拒绝进入文件夹。任何帮助将不胜感激。

ubuntu@ip-123-123-123-123:/var/www$ sudo chmod -R 644 html/
ubuntu@ip-123-123-123-123:/var/www$ cd html
-bash: cd: html: Permission denied
ubuntu@ip-123-123-123-123:/var/www$ sudo adduser ubuntu sudo
The user `ubuntu' is already a member of `sudo'.
ubuntu@ip-123-123-123-123:/var/www$ sudo cd html/
sudo: cd: command not found

权限文件

ubuntu@ip-123-123-123-123:/var/www$  sudo cat /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults    env_reset
Defaults    mail_badpass
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

“sudo ls -ld html”输出

ubuntu@ip-123-123-123-123:/var/www$ sudo ls -ld html/
drw-r--r-- 17 ubuntu root 4096 Feb  7 17:49 html/

“sudo ls -l html/”输出

ubuntu@ip-123-123-123-123:/var/www$ sudo ls -l html/
total 140
drw-r--r-- 10 root root  4096 Feb  7 17:49 app
drw-r--r--  2 root root  4096 Feb  7 17:49 bin
drw-r--r--  5 root root  4096 Feb  7 17:49 config
-rw-r--r--  1 root root   154 Feb  7 17:49 config.ru
drw-r--r--  3 root root  4096 Feb  7 17:49 coverage
-rw-r--r--  1 root root   297 Feb  7 17:49 custom_plan.rb
drw-r--r--  3 root root  4096 Feb  7 17:49 db
drw-r--r--  3 root root  4096 Feb  7 17:49 doc
-rw-r--r--  1 root root  4335 Feb  7 17:49 Gemfile
-rw-r--r--  1 root root 12764 Feb  7 17:49 Gemfile.lock
-rw-r--r--  1 root root  1201 Feb  7 17:49 Guardfile
-rw-r--r--  1 root root    72 Feb  7 17:49 instructions
drw-r--r--  5 root root  4096 Feb  7 17:49 lib
-rw-r--r--  1 root root  1090 Feb  7 17:49 LICENSE
drw-r--r--  2 root root  4096 Feb  7 17:49 log
-rw-r--r--  1 root root    26 Feb  7 17:49 problems_with_dashboard_solutions?
-rw-r--r--  1 root root   179 Feb  7 17:49 Procfile
-rw-r--r--  1 root root   210 Feb  7 17:49 project.sublime-project
drw-r--r--  3 root root  4096 Feb  7 17:49 public
-rw-r--r--  1 root root   249 Feb  7 17:49 Rakefile
-rw-r--r--  1 root root   768 Feb  7 17:49 README
-rw-r--r--  1 root root 12087 Feb  7 17:49 README.rdoc
drw-r--r-- 13 root root  4096 Feb  7 17:49 spec
drw-r--r--  3 root root  4096 Feb  7 17:49 test
drw-r--r--  6 root root  4096 Feb  7 17:51 tmp
-rw-r--r--  1 root root   490 Feb  7 17:49 TODO
-rw-r--r--  1 root root   513 Feb  7 17:49 Vagrantfile
drw-r--r--  3 root root  4096 Feb  7 17:49 vendor
-rw-r--r--  1 root root   470 Feb  7 17:49 zeus.json

【问题讨论】:

    标签: ubuntu permissions


    【解决方案1】:

    为了将cd 放入目录,如果您不是所有者,也不是所有者组的成员,您需要在其他人中使用5(r-x)

    例子:

    whoami
    tiago
    sudo mkdir test ; sudo chown root.root test; sudo chmod 644 test
    cd test
    bash: cd: test: Permission denied
    

    给别人5个:

    sudo chmod 645 test
    cd test
    pwd
    /tmp/test 
    

    但是将5(r-x) 提供给其他人是一个非常糟糕的主意。你最好改变它的所有权:

    chown ubuntu.www-data html/
    

    PS。 www-data 是 apache 使用的用户。您可能需要根据您使用的 Web 服务器选择另一个组。

    【讨论】:

    • 我正在使用 apache,但这仍然给我一个错误。我似乎也被锁定在读取权限之外
    • 能不能把ls -l html/ls -ld html/的输出加起来
    • 您现在看到问题了吗? root.root 拥有的一切:sudo chown -R ubuntu.www-data html/ 应该可以解决您的问题。
    • 我需要给自己 744 权限才能访问该文件夹。这是正常的吗?我以为通常是 644。
    • 如果你是644的主人应该做的。现在解决了吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    • 2019-05-09
    • 1970-01-01
    • 1970-01-01
    • 2018-03-12
    • 2016-02-17
    • 2018-01-22
    相关资源
    最近更新 更多