LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-05-2020, 01:19 PM   #1
pwjohnston
LQ Newbie
 
Registered: Jul 2009
Distribution: Fedora/CentOS
Posts: 20

Rep: Reputation: 1
Having a problem understanding sudo and setting environmental variables


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 up
boxes are stored in
Code:
# ll /root/.vagrant.d/boxes
total 0
drwxr-xr-x. 3 root root 37 May  5 13:40 minimal-VAGRANTSLASH-centos7
The 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% /var
Per 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/vagrant
So I did
Code:
# cp -r ./.vagrant.d/ /var
then deleted the box file from
/root/.vagrant.d/boxes

and
Code:
$ export VAGRANT_HOME=/var/.vagrant.d
run
Code:
$ sudo vagrant up
and 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_profile
drop back into my user profile

Code:
$ sudo vagrant up
boxes 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-centos7
I 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.
 
Old 05-05-2020, 01:39 PM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
By default, sudo retains only a few select variables from the user environment. To change this, see
1) the sudo option -E / --preserve-env;
2) description of the env_keep setting in sudoers(5).
 
Old 05-05-2020, 01:42 PM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,333
Blog Entries: 3

Rep: Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729
Close. sudo runs the designated command as another user entirely for the duration of that command. If no use is designated at runtime then the default is root. You'll want to look more closely at some of the options you pass to sudo, such as --preserve-env or --preserve-env=... where ... is the list of variables to pass over to the new user. You may have to edit /etc/sudoers to list the variables allowed.

Code:
...
Defaults        env_keep+="FOO"
Defaults        env_keep+="BAR"
...
 
Old 05-05-2020, 02:46 PM   #4
pwjohnston
LQ Newbie
 
Registered: Jul 2009
Distribution: Fedora/CentOS
Posts: 20

Original Poster
Rep: Reputation: 1
That -E environment option seems to be what I was missing.

Code:
$ printenv | grep VAGRANT
VAGRANT_HOME=/var/.vagrant.d/

$ sudo -E vagrant up

$ ls -lah /var/.vagrant.d/boxes/
total 12K
drwxr-xr-x. 3 root root 4.0K May  5 15:40 .
drwxrwxrwx. 7 root root 4.0K May  5 15:39 ..
drwxr-xr-x. 3 root root 4.0K May  5 15:40 minimal-VAGRANTSLASH-centos7
Thank you shruggy and Turbocapitalist.
 
  


Reply

Tags
env, environment variable, environment variables, sudo



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Clarification setting environmental Variables JAVA_Home and JDK_HOME econ8193 Linux - Newbie 1 09-25-2012 07:16 AM
Sun Grid Engine: setting environmental variables coenvh Linux - General 0 03-19-2010 05:14 AM
setting environmental variables permanently geetha_sg Slackware 6 08-10-2008 05:14 PM
Setting environmental variables Ninju Linux - Newbie 3 09-25-2007 04:29 PM
Setting environmental variables in mandrake inprogress Linux - Newbie 4 06-07-2003 08:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration