How to ssh linux when the shell is changed or crashed, but still need to have access remotely?

0

I have remote location Linux running (CentOS 6.0). It has dynamic ip address so i installed noip2 service and copied the file cp redhat.noip2.sh /etc/profile.d/noip.sh.

Here you can see the noip.sh script running now for ever on reboot (see).

After that when the system restarted once, it never have the correct shell. As a result remotely when i try to ssh the server i cant login and i cant do anything. Can anyone solve this? Here is the details i tried: When i debug the ssh i see that debug1: Authentication succeeded (password). and command is also sent but nothing just happen. I simply cant fix it yet.

All failed:

ssh root@host 'rm -fr /etc/profile.d/noip.sh'
scp emptynoip.sh root@host:/etc/profile.d/noip.sh
ssh root@host /bin/sh
ssh root@host /bin/bash
ssh root@host --norc -i
ssh root@host -- --norc -i
ssh root@host bash --norc -i 
ssh root@host /bin/bash -i './etc/profile.d/noip2 stop'
ssh root@host /bin/bash -i './etc/profile.d/noip stop'
ssh root@host /bin/bash -l './etc/profile.d/noip stop'

many more... combination i tried all failed. Is there any single option that i can try?

YumYumYum

Posted 2011-08-29T15:04:07.457

Reputation: 1 399

What happens when you tried these exactly? Did you get an error message? If so, what error? – David Schwartz – 2011-08-29T15:56:17.590

For future reference: calling noip services from /etc/profile.d is a bad idea. (Situation: server reboots, obtains a different address, but DNS is not updated since profile.d is launched at login time, and you cannot login without updating DNS first...) Use /etc/rc.local or similar instead. – user1686 – 2011-08-29T16:16:40.050

What happens when you try pressing Ctrl-C after the "sent command" message is displayed? In most shells, profile files can be interrupted that way. Ctrl-Z and Ctrl-\ may work too. – user1686 – 2011-08-29T16:17:42.937

I tried to put on-site someone to physically remove the /etc/profile.d/noip.sh and apply init 6. But on-site with keyboard they cant login either using username root and password. Always they get login prompt now. Ctrl-c i cant apply its very small duration we have in that period. – YumYumYum – 2011-08-29T16:21:41.900

Can i send remotely ssh root@host 'ctrl-c or ctrl-z' ? – YumYumYum – 2011-08-29T16:22:07.030

Here is the details: https://gist.github.com/1178759

– YumYumYum – 2011-08-29T16:24:42.020

I don't really understand your question.. But just to be sure, the command-line application "screen" won't resolve this for you?? – James T Snell – 2011-08-29T16:42:22.627

@Doc, if you put the above script in your /etc/profile.d/noip.sh and then do #ssh localhost and try to login you will see you cant login anymore. That is my problem. – YumYumYum – 2011-08-29T16:58:10.857

@89899.3K No, you cannot, because those are not commands. Those are keys you have to press after running ssh root@host and logging in. – user1686 – 2011-08-29T18:37:26.937

@grawity: I installed a virtualbox. With Debian and there i copy and paste the noip.sh script into /etc/profile.d/noip.sh and then if i do ssh localhost it shows noip.sh but if i apply ssh localhost 'init 6' it reboots. But i cant do that in CentOS? – YumYumYum – 2011-08-29T19:34:58.320

Thanks it was solved finally, i placed the correct steps for future reference. – YumYumYum – 2011-09-03T22:19:22.600

Answers

0

Solved.

Steps:

  • i was physically into the server
  • then i still cant login it always ask login prompt even physically trying to login
  • So i went to grub menu by pressing shift key and still the same, it always ask login prompt (do not allow me to change even run level)

Solution:

  1. While booting press shift key
  2. Grub menu press a
  3. add this "init=/bin/sh"
  4. shell appear, then apply rm -fr /etc/profile.d/noip.sh (failed because read only)

  5. mount, unmount /

  6. rm -fr /etc/profile.d/noip.sh worked

  7. init 6 (failed)

  8. turn the power-off and turn it on (solved the whole crap)

Still now no more issue on this, so its solved, have no problem now. Hope it helps others in future. (do not ever put something in /etc/profile.d/...)

YumYumYum

Posted 2011-08-29T15:04:07.457

Reputation: 1 399

1

Two possible solutions:

  • login as another user and then use sudo or su to remove noip.sh
  • use sftp to remove noip.sh

As a side note, for the dynamic ip problem ddclient is a more robust solution, it support many services, ifup/down hooks and also a daemon mode.

Pablo Castellazzi

Posted 2011-08-29T15:04:07.457

Reputation: 931

I can not login physically either. It prompts login and again prompt login and again prompt login even providing valid password. – YumYumYum – 2011-08-29T19:30:13.740

I cant even su - it always run the noip.sh. I was testing in a VirtualBox by putting the noip.sh in /etc/profile.d/noip.sh – YumYumYum – 2011-08-29T19:30:50.867

Tried with Sftp, connection is auto closed always. – YumYumYum – 2011-08-29T19:32:43.673

su - is the same as running the root account shell, try with su -s /bin/dash (or another shell listed in /etc/shells, csh family of shells are good candidates, they use different configuration files) – Pablo Castellazzi – 2011-08-30T03:49:16.077

Thanks it was solved finally, i placed the correct steps for future reference. – YumYumYum – 2011-09-03T22:19:39.683