You are not logged in.

#1 2015-08-20 17:29:54

nlern
Member
From: West Bengal, India
Registered: 2015-06-29
Posts: 51

[SOLVED] sudo -i not loading root's .bashrc

Hello, I recently reinstalled Arch linux and installed KDE 5 Plasma.

In my bash prompt, if I type:

sudo -i

default bashrc gets loaded and I have to manually enter:

source .bashrc

to get my bash settings for root. I want to automate this. So can anyone help me on this issue?

EDIT: This is my bashrc:

#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls --color=auto'
#PS1='[\u@\h \W]\$ '	#Default
PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\W\[\e[m\] \[\e[1;32m\]\$\[\e[m\] \[\e[1;37m\]'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

 # don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

Last edited by nlern (2015-08-21 18:23:01)

Offline

#2 2015-08-20 17:37:05

CyberLard
Member
Registered: 2015-08-07
Posts: 10

Re: [SOLVED] sudo -i not loading root's .bashrc

Is there a .bashrc file in /root? i.e. /root/.bashrc

That is what will get read. You can symlink it if you want.

Offline

#3 2015-08-20 17:46:13

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: [SOLVED] sudo -i not loading root's .bashrc

nlern wrote:

default bashrc

Specify the whole path, e.g. /etc/bashrc, /root/.bashrc - then it's clear what you mean.

Offline

#4 2015-08-20 18:18:39

Fixxer
Member
From: Poland
Registered: 2011-08-29
Posts: 232

Re: [SOLVED] sudo -i not loading root's .bashrc

Look here - what files are sourced by login and non-login shells:
https://wiki.archlinux.org/index.php/Ba … tion_files .

Offline

#5 2015-08-21 12:54:24

nlern
Member
From: West Bengal, India
Registered: 2015-06-29
Posts: 51

Re: [SOLVED] sudo -i not loading root's .bashrc

Hello all, I'd created a .bashrc in '/root' but every time I enter 'sudo -i', the default profile (maybe the one in /etc/bashrc, don't know for sure, but its the one that loads on a freshly installed Arch with empty Home Directory) gets loaded.

EDIT: I'm using the same .bashrc for my regular user home directory and root directory. Basically, I want BASH to load .bashrc in root folder after entering 'sudo -i'.

Last edited by nlern (2015-08-21 13:11:04)

Offline

#6 2015-08-21 13:55:43

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,648

Re: [SOLVED] sudo -i not loading root's .bashrc

What happens when you log in as root (not using sudo -i, just logging in from the login prompt)? Does the root bashrc get loaded then? Did you read the link Fixxer provided? Do you have a .profile or .bash_profile file in root's home directory?

Last edited by 2ManyDogs (2015-08-21 13:57:06)

Offline

#7 2015-08-21 14:09:34

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: [SOLVED] sudo -i not loading root's .bashrc

AFAIK, sudo is not supposed to source the root user's bashrc.  This is sudo, not su.  If you want to log in as root, use su - that's what it's for.  sudo allows regular users to temporarily have elevated access - but you are still logged in as your regular user.

man sudo wrote:

-i
    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 or .login will be read by the shell.  If a command is specified, it is passed to the shell for execution via the shell's -c option.  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.  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.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#8 2015-08-21 15:36:05

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED] sudo -i not loading root's .bashrc

Trilby, that man page mostly contradicts what you wrote? It explicitly says that it causes the shell to read login-specific resource files for the target user (usually root without -u option). `sudo -i` should be similar to `su -` or a normal login like 2ManyDogs suggests.

If root's shell is bash, then /root/.bash_profile and/or /root/.profile should be read for the interactive login shell started by `sudo -i`. /root/.bashrc will not be read directly, but it may be executed by /root/.bash_profile (which we haven't seen yet). Fixxer already provided a relevant wiki link but that seems to have gone unnoticed.

Offline

#9 2015-08-21 16:59:42

nlern
Member
From: West Bengal, India
Registered: 2015-06-29
Posts: 51

Re: [SOLVED] sudo -i not loading root's .bashrc

Hello, trying 2ManyDogs suggestion I logged in as 'root' in ttys 2,3 and '/root/.bashrc' was not loaded. Also, @2ManyDogs, I did a quick overview of the table on the link provided by Fixxer and finally, no, I do not have .bash_profile, .profile in my /root directory.

EDIT: Thanks Raynman, I'll try to do a in-depth reading of the Fixxer provided link. Actually I posted this question to get a quick solution.

Last edited by nlern (2015-08-21 17:02:44)

Offline

#10 2015-08-21 17:05:51

nlern
Member
From: West Bengal, India
Registered: 2015-06-29
Posts: 51

Re: [SOLVED] sudo -i not loading root's .bashrc

Hello guys, thank you all very much! I had a .bash_profile in my normal home directory and after copying it to root folder, voila! the .bashrc was loaded. Marking the thread as solved.

Offline

#11 2015-08-21 17:08:41

Fixxer
Member
From: Poland
Registered: 2011-08-29
Posts: 232

Re: [SOLVED] sudo -i not loading root's .bashrc

Compare it "for tranquility" with /etc/skel/.bash_profile ;]

Marking the thread as solved.

--force-good ;]

Last edited by Fixxer (2015-08-21 17:09:57)

Offline

Board footer

Powered by FluxBB