Article 532RC Having a problem understanding sudo and setting environmental variables

Having a problem understanding sudo and setting environmental variables

by
pwjohnston
from LinuxQuestions.org on (#532RC)
Hello,

I'm having difficulty understanding sudo and environmental variables.

I'm currently setting up vagrant on a host so I can play with adding and removing linux VMs and try and learn Linux better. Host is CentOS 7.

When I run
Code:$ sudo vagrant upboxes are stored in
Code:# ll /root/.vagrant.d/boxes
total 0
drwxr-xr-x. 3 root root 37 May 5 13:40 minimal-VAGRANTSLASH-centos7The problem with this, however, is I only have 25 GB on that partition.
Code:$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 25G 11G 14G 45% /I have set up var to store data
Code:$df -h /var
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg--1tb--mirror-var--mirror 197G 43G 145G 23% /varPer this post I found that I can set the environmental variable for vagrant to put the Vagrant boxes somewhere else.
https://stackoverflow.com/questions/...he-home-folder

Code:export VAGRANT_HOME=/path/to/vagrantSo I did
Code:# cp -r ./.vagrant.d/ /varthen deleted the box file from
/root/.vagrant.d/boxes

and
Code:$ export VAGRANT_HOME=/var/.vagrant.drun
Code:$ sudo vagrant upand the box is still saved in
/root/.vagrant.d/boxes

So I'm thinking maybe sudo runs a command as root and not just with root permission? I do the same process over again

Code:$su -
# vi ~/.bash_profile
add the line
export VAGRANT_HOME=/var/.vagrant.d
# cat ~/.bash_profile | grep VAGRANT
export VAGRANT_HOME=/var/.vagrant.d/

# source ~/.bash_profiledrop back into my user profile

Code:$ sudo vagrant upboxes are still being saved to

Code:$ sudo ls -lah /root/.vagrant.d/boxes
[sudo] password for langenoir:
total 0
drwxr-xr-x. 3 root root 42 May 5 14:07 .
drwxr-xr-x. 7 root root 119 May 5 14:07 ..
drwxr-xr-x. 3 root root 37 May 5 14:07 minimal-VAGRANTSLASH-centos7I really don't understand what is going on here. I keep reading that sudo elevates user permissions. I thought that means it gives my user root permissions temporarily to run a command. I'm guessing that is wrong.latest?d=yIl2AUoC8zA latest?i=eTa5ep3QrNA:Y7qmTSZZGvo:F7zBnMy latest?i=eTa5ep3QrNA:Y7qmTSZZGvo:V_sGLiP latest?d=qj6IDK7rITs latest?i=eTa5ep3QrNA:Y7qmTSZZGvo:gIN9vFweTa5ep3QrNA
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments