SSH to a remote linux machine shows -bash: /root/.bashrc: Permission denied warning

The following are the steps I performed:

  1. SSH to a CentOS 6.x machine that is in the local network with command

ssh root@192.168.0.1

  1. Enter the root user password
  2. 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:

  1. I am able to login to any other machine in the local network without having this issue.
  2. 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/.bashrc 

Bashrc 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?

9

1 Answer

-bash: /root/.bashrc: Permission denied

  • Check the permissions of .bashrc file (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/bashrc is including.

  • Check the permissions of your /etc folder (see this post). For example:

     chmod 0755 /etc # run as root 
  • Consider adding -vvv when running ssh for more detailed output.


Tracing

To further debug the problem, you can enable tracing (xtrace) in your shell. Here are 3 methods:

  1. Using shebang.

    Add the following line as the first one to your script:

     #!/bin/bash -x 
  2. Add set -x line at the very start of your startup script file.

  3. Run bash with -x along with ssh command, 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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like