The following are the steps I performed:
- SSH to a CentOS 6.x machine that is in the local network with command
ssh root@192.168.0.1
- Enter the root user password
- I was able to successfully login to the machine, but I only get the bash terminal instead of the root user terminal.
Last login: Wed Apr 25 18:04:32 2018 from 192.168.0.27
-bash: /root/.bashrc: Permission denied
-bash-4.1#
I am trying to understand what is the problem here.
Additional info:
- I am able to login to any other machine in the local network without having this issue.
- Also, from the bash terminal, I am able to switch to the super user account with "su" command.
Few command executed on the remote machine which I'm trying to login and its output.
-bash-4.1# whoami
root
-bash-4.1# stat /root/.bashrc
File: `/root/.bashrc'
Size: 221 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 32510289 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-04-26 10:09:04.206129757 +0530
Modify: 2018-04-25 18:04:59.354903860 +0530
Change: 2018-04-25 18:04:59.389903855 +0530
-bash-4.1# file /root/.bashrc
/root/.bashrc: ASCII text
-bash-4.1# lsattr /root/.bashrc
-------------e- /root/.bashrcBashrc content:
#/bin/bash -x
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then . /etc/bashrc
fi
export PATH="/opt/postgres/postgresql:$PATH"Can anyone please help me understand this?
91 Answer
-bash: /root/.bashrc: Permission denied
Check the permissions of
.bashrcfile (which you did).Check the permissions of all files which you're including (such as
/etc/bashrc).Check the permissions of all files which your global
/etc/bashrcis including.Check the permissions of your
/etcfolder (see this post). For example:chmod 0755 /etc # run as rootConsider adding
-vvvwhen runningsshfor more detailed output.
Tracing
To further debug the problem, you can enable tracing (xtrace) in your shell. Here are 3 methods:
Using shebang.
Add the following line as the first one to your script:
#!/bin/bash -xAdd
set -xline at the very start of your startup script file.Run
bashwith-xalong withsshcommand, e.g.\ssh -vvv root@192.168.0.1 -t bash -x
After that, try to reproduce the issue again, then you should find the problematic line.
2