LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-09-2015, 03:39 PM   #1
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,116

Rep: Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530
Added 'exit 0' to the bottom of .bashrc, now what?


Centos 6.5

I ran into an interesting problem (on reddit) that I figured I could solve, but I have not been able to. Its simple,.. I added 'exit 0' to /root/.bashrc, and now I am trying to log in via ssh.

Everytime I do, it immediately exits when it runs the .bash_profile, which sources .bashrc, (which is immediate upon 'logging in')

I've tried:

Code:
ssh root@192.168.1.50 -t vim
vim scp://192.168.1.50/.bashrc
vim scp://192.168.1.50/root/.bashrc
ssh root@192.168.1.50 bash --norc
ssh root@192.168.1.50 /bin/bash --norc --noprofile
ssh -T root@192.168.1.50 "mv /root/.bashrc /root/.bashRC"
scp .bashrc root@192.168.1.50:/root/
ssh root@192.168.1.50 /bin/bash --norc --noprofile -vvvvvvvvvv
ssh -vvvvvv root@192.168.1.50 /bin/bash --norc --noprofile
ssh -vvvvvv root@192.168.1.50 /bin/mv /root/.bashrc /root/.bashRC
ssh -t -t root@192.168.1.50 << EOF
mv /root/.bashrc /root/.bashRC
EOF
ssh -t -t root@192.168.1.50 --norc << EOF
echo HELLO > /root/.bashrc
EOF
ssh -tv root@192.168.1.50 rm .bashrc
So,.. I am unable to get back into the system (as root, no other users exist) after adding 'exit 0' to .bashrc

Anyone feel like explaining why all of these failed (aside from saying SSH interactive logins run the .bash_profile/.bashrc files) or, offering a suggestion that works? Seems like if you have the root password, you should be allowed to modify the login process... since... you know... you are root.

Last edited by szboardstretcher; 03-09-2015 at 04:03 PM.
 
Old 03-09-2015, 04:01 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,817

Rep: Reputation: 609Reputation: 609Reputation: 609Reputation: 609Reputation: 609Reputation: 609
If all of those failed to let you edit .bashrc or remove it, then you have a different problem than just an exit.
Also, hi from Reddit (though that guy says he fixed it).
 
Old 03-09-2015, 04:05 PM   #3
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,116

Original Poster
Rep: Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530
Correct. Tried all the solutions, none work. I have access to the machine, it works fine until I put exit 0 at the bottom of .bashrc

After that, no combination of --norc --noprofile, scp, sftp, /bin/bash, commands etc etc have any affect at all. Its literally a base install of centos built for this testing only. Everything is default except the 'exit 0' at the bottom of .bashrc
 
Old 03-09-2015, 04:26 PM   #4
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,817

Rep: Reputation: 609Reputation: 609Reputation: 609Reputation: 609Reputation: 609Reputation: 609
Boot the machine from live CD at the console and edit /root/.bashrc from there.
 
Old 03-09-2015, 04:45 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
Ummm... don't do that.

bashrc is run in the same context as the users login shell - thus an exit logs the user out.

And in the list of things of "don't put exit in":
.login
.profile
.bashrc
.cshrc
.xinit
.xsession

Exits can be used in any script that is not run as part of the users login shell - all it does then is terminate the process. It can be used in other places - but you have to expect to be logged out.
 
Old 03-10-2015, 10:58 AM   #6
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,116

Original Poster
Rep: Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530
Quote:
Originally Posted by AlucardZero View Post
Boot the machine from live CD at the console and edit /root/.bashrc from there.
No. I believe you are missing the point. If you put 'exit 0' in your .bashrc,.. is it ever possible to 'remotely' access the machine again?

Its a virtual machine built for testing this. Of course I can boot into single user mode and edit it, but that isnt the point.
 
Old 03-10-2015, 11:00 AM   #7
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,116

Original Poster
Rep: Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530
Quote:
Originally Posted by jpollard View Post
Ummm... don't do that.

bashrc is run in the same context as the users login shell - thus an exit logs the user out.

And in the list of things of "don't put exit in":
.login
.profile
.bashrc
.cshrc
.xinit
.xsession

Exits can be used in any script that is not run as part of the users login shell - all it does then is terminate the process. It can be used in other places - but you have to expect to be logged out.
Agreed. But,. if you were to accidentally do that,. how could you bypass the .bashrc to remotely log in? Some people and distros are reporting that the --norc option works. Why does it work on their distro but not Centos 6.5 default install? What is different? That is the real discussion here, not whether its possible, but why Centos 6.5 root user is unable to diable bashrc remotely when logging in...
 
Old 03-10-2015, 11:13 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
Well I am no ssh guru, but I found one idea and had a left of centre one:

Found:
Code:
~/.ssh/rc
              Commands in this file are executed by ssh when the user logs in, just before the user's shell (or command) is started.
Idea: By default the nobody user is often part of the core system. Could you login as that user??
 
Old 03-10-2015, 11:17 AM   #9
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,362

Rep: Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004
What if you were to use sshfs to remotely mount root's home directory on another machine and edit it there?
 
Old 03-10-2015, 11:25 AM   #10
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
Quote:
Originally Posted by szboardstretcher View Post
Agreed. But,. if you were to accidentally do that,. how could you bypass the .bashrc to remotely log in? Some people and distros are reporting that the --norc option works. Why does it work on their distro but not Centos 6.5 default install? What is different? That is the real discussion here, not whether its possible, but why Centos 6.5 root user is unable to diable bashrc remotely when logging in...
you could try with the kernel parameter "init=/bin/bash --noprofile". But I admit to being unfamiliar with passing parameters to init. I think it has to be the last entry of the boot command.
 
Old 03-10-2015, 11:55 AM   #11
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,305

Rep: Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816
Brain isn't working well today but how about using rsync or scp to copy over an "empty" .bashrc file?
 
Old 03-10-2015, 12:07 PM   #12
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
Quote:
Originally Posted by TenTenths View Post
Brain isn't working well today but how about using rsync or scp to copy over an "empty" .bashrc file?
I believe sshd runs the bashrc scripts to setup the shell used to finish running the local scp (which runs very much like "cat > file"... Now an external rsync server might not.

Anything that terminate the shell will also terminate the scp.
 
Old 03-10-2015, 12:09 PM   #13
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,305

Rep: Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816
Quote:
Originally Posted by jpollard View Post
I believe sshd runs the bashrc scripts to setup the shell used to finish running the local scp (which runs very much like "cat > file"... Now an external rsync server might not.

Anything that terminate the shell will also terminate the scp.
Makes sense, like I said, bad brain day! Although I'm now fascinated and may muck about with a VM tomorrow to try it!
 
Old 03-10-2015, 06:18 PM   #14
sgrlscz
Member
 
Registered: Aug 2008
Posts: 53

Rep: Reputation: 20
Quote:
Originally Posted by szboardstretcher View Post
Agreed. But,. if you were to accidentally do that,. how could you bypass the .bashrc to remotely log in? Some people and distros are reporting that the --norc option works. Why does it work on their distro but not Centos 6.5 default install? What is different? That is the real discussion here, not whether its possible, but why Centos 6.5 root user is unable to diable bashrc remotely when logging in...
They fail because the sshd process is invoking the root's shell to call the command, i.e. sshd isn't running:

Code:
/bin/bash --norc --noprofile
It's actually running:

Code:
bash -c /bin/bash --norc --noprofile
Since it's invoking the shell in order to run the command, it's exiting before it even gets to the command being passed, so it never runs the '/bin/bash --norc --noprofile'.

I haven't looked at the sshd code to see if maybe there are different options to give different behaviors or if there is something in the default configs, which might explain the distribution differences.

With the way Centos and RHEL are working, I don't see a way to get it to work because I can't see a way to either stop the processing of the .bashrc or override the shell.
 
Old 03-10-2015, 06:39 PM   #15
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
That was why I suggested using the kernel parameter "init=/bin/bash --noprofile". This should bypass the system startup and allow you to use the initrd to do things (like mount root and fix things).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] /etc/bashrc ,dircolors and /root/.bash_profile ,/.bashrc not exist in LFS-7.5(sec9.3) jaassi Linux From Scratch 2 09-20-2014 06:04 PM
How to exit from bashrc Subhabose Ubuntu 3 05-30-2014 08:01 AM
[SOLVED] LD_LIBRARY_PATH added to .bashrc but only works if apps launched from terminal snowweb Linux - Desktop 7 10-15-2011 12:38 AM
"exit" in bash .bashrc procedure/shell function exits xterm anonguy9 Linux - Newbie 11 07-13-2011 04:54 PM
[SOLVED] I put an 'exit' in my /etc/bashrc and now can't open a terminal or modify! unityxx311 Linux - Newbie 9 08-19-2010 10:56 AM


All times are GMT -5. The time now is 01:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration