Set up env variable when sudo as apache user
Clash 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?
centos
 |Â
show 1 more comment
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?
centos
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
 |Â
show 1 more comment
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?
centos
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?
centos
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
 |Â
show 1 more comment
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
 |Â
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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