Set up env variable when sudo as apache user

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I have centos 7 webserser, all site's files within wwwsitenamehtdocs belong to user 'apache'.



Sometimes i need git pull as apache user, that's why i wrote simple script to sudo as apache:



[ansible@vm123123 ~]$ cat ~/suwu.sh
#!/bin/sh

sudo setfacl -m apache:x $(dirname "$SSH_AUTH_SOCK")
sudo setfacl -m apache:rwx "$SSH_AUTH_SOCK"

sudo -E su -s /bin/sh apache
[ansible@vm123123 ~]$


And it works well, i can log in as apache user, change files and forward my SSH key to git server.



But can't start mc as apache:



sh-4.2$ mc

(mc:36339): GLib-WARNING **: GError set over the top of a previous GError or uninitialized memory.
This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
The overwriting error message was: Cannot create "/usr/share/httpd/.cache/mc"

(mc:36339): GLib-WARNING **: GError set over the top of a previous GError or uninitialized memory.
This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
The overwriting error message was: Cannot create "/usr/share/httpd/.local/share/mc"
Сбой запуска:
Cannot create "/usr/share/httpd/.config/mc"
sh-4.2$


That's why i run mc like this:



sh-4.2$ MC_HOME=/tmp/MCHOME mc


This works, but is there a way to set up MC_HOME for apache once in my script or somewhere else?







share|improve this question
















  • 1




    You could add: export MC_HOME='/tmp/MCHOME' to your ~/.bash_profile or to the beginning of your script.
    – Jesse_b
    Dec 24 '17 at 12:00










  • @Jesse_b user 'apache' has no home directory via security reason. Exporting variable in script is good idea, one minute...
    – A K
    Dec 24 '17 at 12:02











  • If you aren't concerned with how it will affect other users on that machine you could add it to /etc/profile. Maybe even an alias? alias mca='MC_HOME=/tmp/MCHOME mc'
    – Jesse_b
    Dec 24 '17 at 12:08











  • @Jesse_b Yes, i know about aliases, byt I don't want this way. Exporting variable in script is working, thanks for solution (post it as answer)
    – A K
    Dec 24 '17 at 12:10







  • 1




    My answer is a duplicate of several other answers on this site. I am curious however if there is a "proper" way to set environmental variables for a user with no home directory.
    – Jesse_b
    Dec 24 '17 at 12:12














up vote
3
down vote

favorite












I have centos 7 webserser, all site's files within wwwsitenamehtdocs belong to user 'apache'.



Sometimes i need git pull as apache user, that's why i wrote simple script to sudo as apache:



[ansible@vm123123 ~]$ cat ~/suwu.sh
#!/bin/sh

sudo setfacl -m apache:x $(dirname "$SSH_AUTH_SOCK")
sudo setfacl -m apache:rwx "$SSH_AUTH_SOCK"

sudo -E su -s /bin/sh apache
[ansible@vm123123 ~]$


And it works well, i can log in as apache user, change files and forward my SSH key to git server.



But can't start mc as apache:



sh-4.2$ mc

(mc:36339): GLib-WARNING **: GError set over the top of a previous GError or uninitialized memory.
This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
The overwriting error message was: Cannot create "/usr/share/httpd/.cache/mc"

(mc:36339): GLib-WARNING **: GError set over the top of a previous GError or uninitialized memory.
This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
The overwriting error message was: Cannot create "/usr/share/httpd/.local/share/mc"
Сбой запуска:
Cannot create "/usr/share/httpd/.config/mc"
sh-4.2$


That's why i run mc like this:



sh-4.2$ MC_HOME=/tmp/MCHOME mc


This works, but is there a way to set up MC_HOME for apache once in my script or somewhere else?







share|improve this question
















  • 1




    You could add: export MC_HOME='/tmp/MCHOME' to your ~/.bash_profile or to the beginning of your script.
    – Jesse_b
    Dec 24 '17 at 12:00










  • @Jesse_b user 'apache' has no home directory via security reason. Exporting variable in script is good idea, one minute...
    – A K
    Dec 24 '17 at 12:02











  • If you aren't concerned with how it will affect other users on that machine you could add it to /etc/profile. Maybe even an alias? alias mca='MC_HOME=/tmp/MCHOME mc'
    – Jesse_b
    Dec 24 '17 at 12:08











  • @Jesse_b Yes, i know about aliases, byt I don't want this way. Exporting variable in script is working, thanks for solution (post it as answer)
    – A K
    Dec 24 '17 at 12:10







  • 1




    My answer is a duplicate of several other answers on this site. I am curious however if there is a "proper" way to set environmental variables for a user with no home directory.
    – Jesse_b
    Dec 24 '17 at 12:12












up vote
3
down vote

favorite









up vote
3
down vote

favorite











I have centos 7 webserser, all site's files within wwwsitenamehtdocs belong to user 'apache'.



Sometimes i need git pull as apache user, that's why i wrote simple script to sudo as apache:



[ansible@vm123123 ~]$ cat ~/suwu.sh
#!/bin/sh

sudo setfacl -m apache:x $(dirname "$SSH_AUTH_SOCK")
sudo setfacl -m apache:rwx "$SSH_AUTH_SOCK"

sudo -E su -s /bin/sh apache
[ansible@vm123123 ~]$


And it works well, i can log in as apache user, change files and forward my SSH key to git server.



But can't start mc as apache:



sh-4.2$ mc

(mc:36339): GLib-WARNING **: GError set over the top of a previous GError or uninitialized memory.
This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
The overwriting error message was: Cannot create "/usr/share/httpd/.cache/mc"

(mc:36339): GLib-WARNING **: GError set over the top of a previous GError or uninitialized memory.
This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
The overwriting error message was: Cannot create "/usr/share/httpd/.local/share/mc"
Сбой запуска:
Cannot create "/usr/share/httpd/.config/mc"
sh-4.2$


That's why i run mc like this:



sh-4.2$ MC_HOME=/tmp/MCHOME mc


This works, but is there a way to set up MC_HOME for apache once in my script or somewhere else?







share|improve this question












I have centos 7 webserser, all site's files within wwwsitenamehtdocs belong to user 'apache'.



Sometimes i need git pull as apache user, that's why i wrote simple script to sudo as apache:



[ansible@vm123123 ~]$ cat ~/suwu.sh
#!/bin/sh

sudo setfacl -m apache:x $(dirname "$SSH_AUTH_SOCK")
sudo setfacl -m apache:rwx "$SSH_AUTH_SOCK"

sudo -E su -s /bin/sh apache
[ansible@vm123123 ~]$


And it works well, i can log in as apache user, change files and forward my SSH key to git server.



But can't start mc as apache:



sh-4.2$ mc

(mc:36339): GLib-WARNING **: GError set over the top of a previous GError or uninitialized memory.
This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
The overwriting error message was: Cannot create "/usr/share/httpd/.cache/mc"

(mc:36339): GLib-WARNING **: GError set over the top of a previous GError or uninitialized memory.
This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
The overwriting error message was: Cannot create "/usr/share/httpd/.local/share/mc"
Сбой запуска:
Cannot create "/usr/share/httpd/.config/mc"
sh-4.2$


That's why i run mc like this:



sh-4.2$ MC_HOME=/tmp/MCHOME mc


This works, but is there a way to set up MC_HOME for apache once in my script or somewhere else?









share|improve this question











share|improve this question




share|improve this question










asked Dec 24 '17 at 11:50









A K

1164




1164







  • 1




    You could add: export MC_HOME='/tmp/MCHOME' to your ~/.bash_profile or to the beginning of your script.
    – Jesse_b
    Dec 24 '17 at 12:00










  • @Jesse_b user 'apache' has no home directory via security reason. Exporting variable in script is good idea, one minute...
    – A K
    Dec 24 '17 at 12:02











  • If you aren't concerned with how it will affect other users on that machine you could add it to /etc/profile. Maybe even an alias? alias mca='MC_HOME=/tmp/MCHOME mc'
    – Jesse_b
    Dec 24 '17 at 12:08











  • @Jesse_b Yes, i know about aliases, byt I don't want this way. Exporting variable in script is working, thanks for solution (post it as answer)
    – A K
    Dec 24 '17 at 12:10







  • 1




    My answer is a duplicate of several other answers on this site. I am curious however if there is a "proper" way to set environmental variables for a user with no home directory.
    – Jesse_b
    Dec 24 '17 at 12:12












  • 1




    You could add: export MC_HOME='/tmp/MCHOME' to your ~/.bash_profile or to the beginning of your script.
    – Jesse_b
    Dec 24 '17 at 12:00










  • @Jesse_b user 'apache' has no home directory via security reason. Exporting variable in script is good idea, one minute...
    – A K
    Dec 24 '17 at 12:02











  • If you aren't concerned with how it will affect other users on that machine you could add it to /etc/profile. Maybe even an alias? alias mca='MC_HOME=/tmp/MCHOME mc'
    – Jesse_b
    Dec 24 '17 at 12:08











  • @Jesse_b Yes, i know about aliases, byt I don't want this way. Exporting variable in script is working, thanks for solution (post it as answer)
    – A K
    Dec 24 '17 at 12:10







  • 1




    My answer is a duplicate of several other answers on this site. I am curious however if there is a "proper" way to set environmental variables for a user with no home directory.
    – Jesse_b
    Dec 24 '17 at 12:12







1




1




You could add: export MC_HOME='/tmp/MCHOME' to your ~/.bash_profile or to the beginning of your script.
– Jesse_b
Dec 24 '17 at 12:00




You could add: export MC_HOME='/tmp/MCHOME' to your ~/.bash_profile or to the beginning of your script.
– Jesse_b
Dec 24 '17 at 12:00












@Jesse_b user 'apache' has no home directory via security reason. Exporting variable in script is good idea, one minute...
– A K
Dec 24 '17 at 12:02





@Jesse_b user 'apache' has no home directory via security reason. Exporting variable in script is good idea, one minute...
– A K
Dec 24 '17 at 12:02













If you aren't concerned with how it will affect other users on that machine you could add it to /etc/profile. Maybe even an alias? alias mca='MC_HOME=/tmp/MCHOME mc'
– Jesse_b
Dec 24 '17 at 12:08





If you aren't concerned with how it will affect other users on that machine you could add it to /etc/profile. Maybe even an alias? alias mca='MC_HOME=/tmp/MCHOME mc'
– Jesse_b
Dec 24 '17 at 12:08













@Jesse_b Yes, i know about aliases, byt I don't want this way. Exporting variable in script is working, thanks for solution (post it as answer)
– A K
Dec 24 '17 at 12:10





@Jesse_b Yes, i know about aliases, byt I don't want this way. Exporting variable in script is working, thanks for solution (post it as answer)
– A K
Dec 24 '17 at 12:10





1




1




My answer is a duplicate of several other answers on this site. I am curious however if there is a "proper" way to set environmental variables for a user with no home directory.
– Jesse_b
Dec 24 '17 at 12:12




My answer is a duplicate of several other answers on this site. I am curious however if there is a "proper" way to set environmental variables for a user with no home directory.
– Jesse_b
Dec 24 '17 at 12:12















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f412796%2fset-up-env-variable-when-sudo-as-apache-user%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f412796%2fset-up-env-variable-when-sudo-as-apache-user%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay