What does sudo -H do?

前端 未结 2 1784
难免孤独
难免孤独 2020-12-07 12:54

After trying to install virtualenv with pip

$ pip install virtualenv

I got a permission denied error

IOError: [Errno 13] Pe         


        
相关标签:
2条回答
  • 2020-12-07 13:10

    -h flag usually means human readable format Its a convenient built in conversion in a Linux OS. for example if you went to your command terminal in Linux in my case a raspberry pi and typed df. This will show you your used and available memory. It will show something like you have 448336 bytes. Your probably like huh that's confusing. Now type in df -h (using the -h flag) you should get a result like this 448M instead of 4488336 bytes.

    0 讨论(0)
  • 2020-12-07 13:16

    Generally

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

    -H

    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.

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

    for example:

     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
    

    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.

    In your Case

    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.

    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.

    0 讨论(0)
提交回复
热议问题