kdb*_*man 4 linux sudo permissions amazon-web-services amazon-ec2
ssh
使用默认的ec2-user
. 我正在尝试列出默认 postgresql 目录的内容:
里面有什么?
$ ls /var/lib/pgsql9/
ls: cannot open directory /var/lib/pgsql9/: Permission denied
Run Code Online (Sandbox Code Playgroud)
好的。谁拥有这个?
$ ls -l /var/lib | grep pgsql
drwx------ 4 postgres postgres 4096 Jun 22 16:06 pgsql9
Run Code Online (Sandbox Code Playgroud)
啊。傻我。
$ sudo -u postgres ls /var/lib/pgsql9/
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for ec2-user:
Run Code Online (Sandbox Code Playgroud)
... 什么?ec2-user
有密码吗?是时候用更大的枪了。
$ sudo sudo -u postgres ls /var/lib/pgsql9/
backups data
Run Code Online (Sandbox Code Playgroud)
成功! 现在,去 superuser.com 看看发生了什么。
sudo sudo
行为与sudo
?Amazon EC2 的构建方式与 Ubuntu 类似:没有root
访问权限,一切都由它来完成sudo
。
您的sudo
命令所做的是尝试模拟postgres
,需要获得许可才能这样做。ec2-user
没有这个权限,所以sudo
会要求输入密码(这将失败,因为它没有密码)。
当您这样做时sudo sudo
,您正在sudo
以具有模拟其他用户权限的 root 身份调用第二个,因此该命令有效。由于sudo
配置方式(sudoers 中的 NOPASSWD 行),它不需要密码即可以 root 身份执行。
归档时间: |
|
查看次数: |
1443 次 |
最近记录: |