LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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-10-2015, 07:57 PM   #16
sgrlscz
Member
 
Registered: Aug 2008
Posts: 53

Rep: Reputation: 20

Quote:
Originally Posted by jpollard View Post
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).
But that's not the question being asked. The question asked was how to bypass the .bashrc via remote login or why it's not working on Centos.

There are plenty of ways to fix it when you have access to the console and can reboot.
 
Old 03-11-2015, 04:26 AM   #17
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Ok ... this worked for me:
Code:
sudo echo "rm /root/.bashrc" > /etc/ssh/sshrc
Then logged in
 
Old 03-11-2015, 05:10 AM   #18
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,171

Rep: Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752
Quote:
Originally Posted by grail View Post
Ok ... this worked for me:
Code:
sudo echo "rm /root/.bashrc" > /etc/ssh/sshrc
Then logged in
Yeah, assuming:
  • You have another user to log in with
  • That user has sudo privilages.
From the OP:
Quote:
Originally Posted by szboardstretcher View Post
So,.. I am unable to get back into the system (as root, no other users exist) after adding 'exit 0' to .bashrc
So.... nice try but no cigar.
 
Old 03-11-2015, 06:40 AM   #19
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by sgrlscz View Post
But that's not the question being asked. The question asked was how to bypass the .bashrc via remote login or why it's not working on Centos.

There are plenty of ways to fix it when you have access to the console and can reboot.
There is no bypass. Only a reboot has the necessary access.

Last edited by jpollard; 03-11-2015 at 06:41 AM.
 
Old 03-11-2015, 07:26 AM   #20
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,171

Rep: Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752
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?
Tried this on my home RasPi and it worked fine, although obviously it's not Redhat/CentOS.
 
Old 03-11-2015, 10:56 AM   #21
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
Anybody tried sshfs as I suggested on the previous page? I put an echo in my .bashrc so I could see every time it gets sourced, and indeed all of the lines in the OP show it sourcing .bashrc before anything happens, but sshfs does not.

Code:
$ ssh server 'bash --norc -c "/bin/ls .bashrc"'
sourcing .bashrc
.bashrc
$ sshfs server:/home/user tempdir
$ vi tempdir/.bashrc

# removed the echo

$ ssh server 'bash --norc -c "/bin/ls .bashrc"'
.bashrc

Last edited by suicidaleggroll; 03-11-2015 at 11:02 AM.
 
Old 03-11-2015, 10:57 AM   #22
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Quote:
Originally Posted by TenTenths View Post
Yeah, assuming:
  • You have another user to log in with
  • That user has sudo privilages.
From the OP:

So.... nice try but no cigar.
I am not sure I understand?? The sudo command I have run is on my computer. I then ssh'ed into the other computer and the rm command was run there as root.

Is this not the desired affect?
 
Old 04-02-2015, 11:49 AM   #23
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,836

Original Poster
Rep: Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360
Lot of good ideas guys. Unfortunately none work on Centos 6.6.

Quote:
Originally Posted by suicidaleggroll View Post
Anybody tried sshfs as I suggested on the previous page? I put an echo in my .bashrc so I could see every time it gets sourced, and indeed all of the lines in the OP show it sourcing .bashrc before anything happens, but sshfs does not.

Code:
$ ssh server 'bash --norc -c "/bin/ls .bashrc"'
sourcing .bashrc
.bashrc
$ sshfs server:/home/user tempdir
$ vi tempdir/.bashrc

# removed the echo

$ ssh server 'bash --norc -c "/bin/ls .bashrc"'
.bashrc
when using sshfs:

Code:
sshfs 192.168.1.5:/root tmp
root@192.168.1.5's password:
remote host has disconnected
It still runs the .bashrc exit 0 command and doesnt mount. Any more information or ideas?

This is a tough nut to crack on Centos. I'm not understanding why all of the 'ignore bashrc' commands and switches do not work. I have successfully done this on Ubuntu with no issue. But I'm guessing that the additional user has a lot to do with that. Perhaps 'root' is locked down further when logging in.

Last edited by szboardstretcher; 04-02-2015 at 11:51 AM.
 
Old 04-02-2015, 11:53 AM   #24
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,836

Original Poster
Rep: Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360
Quote:
Originally Posted by AlucardZero View Post
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).
He fixed it from another account. In this lab setup, this is a minimal Centos 6.5 install with no additional users. Root only. Perhaps this is added security, and I would applaud that - but only with an explanation. If you provide root's password, then you should be in control of the box for better or for worse. Being able to control your login scripts seems like a logical leap from that circumstance.
 
Old 04-02-2015, 12:16 PM   #25
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,836

Original Poster
Rep: Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360
Update: A friend of mine - a developer - hit CTRL-C at the proper moment in the ssh login, and it broke out of the .bashrc file and allowed the login.

While this works - I still would like the answer to my question. WHY are all these ssh flags and parameters being ignored for root?
 
Old 04-02-2015, 12:28 PM   #26
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
So can you confirm that adding to /etc/ssh/sshrc did not work either?
 
Old 04-02-2015, 04:02 PM   #27
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
Quote:
Originally Posted by szboardstretcher View Post
Lot of good ideas guys. Unfortunately none work on Centos 6.6.



when using sshfs:

Code:
sshfs 192.168.1.5:/root tmp
root@192.168.1.5's password:
remote host has disconnected
It still runs the .bashrc exit 0 command and doesnt mount.
You're right, it must have just been suppressing the echo. I set up a VM to test this and I haven't been able to find a way in yet.

Quote:
Originally Posted by szboardstretcher View Post
This is a tough nut to crack on Centos. I'm not understanding why all of the 'ignore bashrc' commands and switches do not work. I have successfully done this on Ubuntu with no issue. But I'm guessing that the additional user has a lot to do with that. Perhaps 'root' is locked down further when logging in.
Because those aren't switches for ssh, they're switches for bash. So ssh is launching a bash session, and inside that bash session it runs "bash --norc" or whatever else you set. The problem is it's the first session that's kicking you out, before it even gets a chance to run "bash --norc".

What you need is a flag to ssh itself that tells it not to source .bashrc when it establishes the connection. Nothing you add or run in the "command" section of ssh is going to make a difference, since it's already sourced .bashrc before any of that is run.

Quote:
Originally Posted by grail
So can you confirm that adding to /etc/ssh/sshrc did not work either?
It does not. It must be sourcing the remote .bashrc before the contents of sshrc are executed on the remote system, because it doesn't seem to make a difference.

Last edited by suicidaleggroll; 04-02-2015 at 04:09 PM.
 
Old 04-02-2015, 04:08 PM   #28
joe_2000
Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 808

Rep: Reputation: 216Reputation: 216Reputation: 216
I had that very problem the other day and I remember I was able to bypass bashrc by using /bin/sh as the shell. I am not sure what the exact syntax was but I think it was something like
Code:
ssh -t /bin/sh user@remotehost
EDIT: Just tried this and it aborts with an error. On second thought I think the problem was with su to root, not the actual remote login.

Last edited by joe_2000; 04-02-2015 at 04:14 PM. Reason: Corrected info
 
Old 04-02-2015, 04:19 PM   #29
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by szboardstretcher View Post
Update: A friend of mine - a developer - hit CTRL-C at the proper moment in the ssh login, and it broke out of the .bashrc file and allowed the login.

While this works - I still would like the answer to my question. WHY are all these ssh flags and parameters being ignored for root?
It is being ignored because of the way the commands are being interpreted:

An ssh to a remote host ALWAYS does the following:

1. verify user (by whatever means)
2. if a command is being passed (ANY command):
2a. executes /bin/sh to interpret the command. Guess what, this is done BEFORE the command is interpreted, and thus processes the .rc file FIRST. An exit there terminates the connection before the command is interpreted. And that includes sshfs or scp.
2b. if the command is an scp, then the scp command is executed with local properties (the "remote file" is now a local file.

I'm not exactly certain of the sequence for sshfs, but I think it is similar - the local sshfs command makes a connection to the sshd service on the remote host, which then executed /bin/sh to interpret a sshfs command with the given target directory - and uses an internal flag to identify it is to provide remote filesystem functions (an RPC service).

As I said, there is no real bypass. You can try the "control C" interrupt - but that depends on a race condition (the interrupt is received before the exit command is processed).
 
Old 04-03-2015, 02:55 AM   #30
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Well I am not sure why my method does not work for others, but I guess I should contact the developers and tell them that the following line should be removed from the man page:
Code:
       /etc/ssh/sshrc
              Commands in this file are executed by ssh when the user logs in, just before the user's shell (or command) is started.  See the sshd(8) manual page for more information.
At least the part in red should be removed if only works on some computers.
 
  


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 11:04 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