sudo -H是做什么的? [英] What does sudo -H do?

查看:1339
本文介绍了sudo -H是做什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用pip安装virtualenv之后

After trying to install virtualenv with pip

$ pip install virtualenv

我遇到了权限被拒绝的错误

I got a permission denied error

IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/virtualenv.py'

所以我用sudo安装virtualenv

So I used sudo to install virtualenv

$ sudo pip install virtualenv

但是随后出现警告:

目录'/Users/petertao/Library/Caches/pip/http'或其父目录 目录不属于当前用户,并且缓存已被 禁用的.请检查该目录的权限和所有者.如果 用sudo执行pip,您可能需要sudo的-H标志.

The directory '/Users/petertao/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

目录'/Users/petertao/Library/Caches/pip'或其父目录 目录不归当前用户所有,并且缓存轮已经 禁用的.检查该目录的权限和所有者.如果 用sudo执行pip,您可能需要sudo的-H标志.

The directory '/Users/petertao/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

sudo的-H标志有什么作用?

推荐答案

通常

man sudo (确切的文本可能有所不同,但是会相似) :

Generally

man sudo (the exact text may vary, but it will be similar):

-H

-H(HOME)选项要求安全策略将HOME环境变量设置为密码数据库指定的目标用户(默认为root)的主目录.根据策略,这可能是默认行为.

The -H (HOME) option requests that the security policy set the HOME environment variable to the home directory of the target user (root by default) as specified by the password database. Depending on the policy, this may be the default behavior.

那么为什么这甚至是一个选择呢? 通常使用"sudo"不会更改$ HOME环境变量.

So why is this even an option? Normally using "sudo" does not change the $HOME environment variable.

例如:

 echo $HOME $USER
/home/testuser testuser

 sudo bash -c 'echo $HOME $USER'
/home/testuser root

 sudo -H bash -c 'echo $HOME $USER'
/home/root root

您可以看到普通的sudo会将我的用户从"testuser"更改为"root",但不会将$ HOME设置为什么,而sudo -H还将变量从"my"主目录更改为root的主目录.

You can see that a normal sudo changes which user I am from "testuser" to "root", but not what $HOME is set to, while a sudo -H also changes the variable from "my" home directory to root's home directory.

pip向您警告它是作为用户root执行的,并且想要修改$ HOME中的内容,该$ HOME设置为'/Users/petertao',该用户不是root拥有的(很可能是"petertao"用户) . 该警告表明pip使用$ HOME缓存文件,但由于文件夹所有权差异而已禁用了自己的缓存.

pip is warning you that it was executed as the user root and wanted to modify things in $HOME, which was set to '/Users/petertao', which is not owned by root (most likely the "petertao" user). the warning indicates that pip uses $HOME to cache files, but has disabled its own caching because of the folder ownership discrepancy.

当然,在以root用户身份执行时,可以修改'/Users/petertao/Library/Caches/pip',因为root(几乎)是万能的. 稍后这会变得很麻烦,因为在没有root用户的情况下运行的程序无法再覆盖或修改这些文件. 而是pip拒绝写入另一个用户拥有的目录.

Of course while executing as root pip can modify '/Users/petertao/Library/Caches/pip' because root is (almost) almighty. This can become troublesome later because a program running without root could no longer overwrite or modify these files. Instead pip refuses to write to a directory owned by another user.

这篇关于sudo -H是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆