Solved Root shell doesn't get environmental variables from .profile

Hi,

I was using /bin/tcsh for both my user and root user and want to switch to /bin/sh but I am unable to make /root/.profile work for root user when I switch to root through security/sudo. /home/$USER/.profile works for the user. Thanks in advance.

Code:
yusuf@hale:~ $ echo $EDITOR
vim
yusuf@hale:~ $ sudo su
Password:
Take a stress pill and think things over.
Password:
You type like i drive.
Password:
root@hale:/home/yusuf # echo $EDITOR


Root shell is set to /bin/sh. This is /root/.profile.

Code:
#
# .profile - Bourne Shell startup script for login shells
#
# see also sh(1), environ(7).
#

# These are normally set through /etc/login.conf.  You may override them here
# if wanted.
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$HOME/.local/bin; export PATH

# Setting TERM is normally done through /etc/ttys.  Do only override
# if you're sure that you'll never log in via telnet or xterm or a
# serial line.
# TERM=xterm;     export TERM

HOME=/root
EDITOR=vim;       export EDITOR
PAGER=vimpager;    export PAGER
LSCOLORS=exfxcxdxbxegedabagacad;    export LSCOLORS
CLICOLOR=1;    export CLICOLOR
BUNDLE_PATH="/home/yusuf/.bundle";    export BUNDLE_PATH
GOPATH="/home/yusuf/.go";    export GOPATH
LANG="en_US.UTF-8";    export LANG
LC_ALL="en_US.UTF-8";    export LC_ALL
BLOCKSIZE="G";    export BLOCKSIZE

# set ENV to a file invoked each time sh is started for interactive use.
ENV=$HOME/.shrc; export ENV
 
Maybe you need option -i (or --login) for sudo(8)?

In sudo(8) manpage:
Code:
     -i, --login
             Run the shell specified by the target user's password database
             entry as a login shell.  This means that login-specific resource
             files such as .profile, .bash_profile, or .login will be read by
             the shell.  If a command is specified, it is passed to the shell
             as a simple command using the -c option.  The command and any
             args are concatenated, separated by spaces, after escaping each
             character (including white space) with a backslash (‘\’) except
             for alphanumerics, underscores, hyphens, and dollar signs.  If no
             command is specified, an interactive shell is executed.  sudo
             attempts to change to that user's home directory before running
             the shell.  The command is run with an environment similar to the
             one a user would receive at log in.  Most shells behave
             differently when a command is specified as compared to an
             interactive session; consult the shell's manual for details.  The
             Command environment section in the sudoers(5) manual documents
             how the -i option affects the environment in which a command is
             run when the sudoers policy is in use.
 
Maybe you need option -i (or --login) for sudo(8)?

In sudo(8) manpage:
Code:
     -i, --login
             Run the shell specified by the target user's password database
             entry as a login shell.  This means that login-specific resource
             files such as .profile, .bash_profile, or .login will be read by
             the shell.  If a command is specified, it is passed to the shell
             as a simple command using the -c option.  The command and any
             args are concatenated, separated by spaces, after escaping each
             character (including white space) with a backslash (‘\’) except
             for alphanumerics, underscores, hyphens, and dollar signs.  If no
             command is specified, an interactive shell is executed.  sudo
             attempts to change to that user's home directory before running
             the shell.  The command is run with an environment similar to the
             one a user would receive at log in.  Most shells behave
             differently when a command is specified as compared to an
             interactive session; consult the shell's manual for details.  The
             Command environment section in the sudoers(5) manual documents
             how the -i option affects the environment in which a command is
             run when the sudoers policy is in use.
It worked! Much appreciated, thanks!
 
Back
Top