5

In my linux machine I'm able to do ssh to the same machine.

[myuser ~]$ssh localhost
Last login: Fri Jul  4 09:59:57 2014 from xxxx
[myuser ~]$

But when I try to run a simple remote command on the same machine using ssh, it hangs/stuck and not returning the control and no output. The command I'm trying to run is

[myuser ~]$ ssh localhost date

The same ssh works if I try from another user from the same machine

[anotheruser ~]$ ssh localhot date
anotheruser@localhost's password:
Fri Jul  4 10:00:39 UTC 2014
[anotheruser ~]$

I have seen other threads for this problem i.e. ssh hanging, But they are different. Please let me know how can I get rid of this. Is this user privileges/groups related issue or something else?

I would like to have the solution as not to modify/add some flags, so this can be resolved. The above is used in some script file and I cant really afford to change that line. Since it is working another user , there should be someway to fix it.

Please help.

Elangovan Manickam
  • 413
  • 1
  • 5
  • 14
  • I hope this link can help you: http://superuser.com/questions/336226/how-to-ssh-to-localhost-without-password – acornagl Jul 04 '14 at 10:25
  • The shared thread is about password less ssh setup. For me entering password is not an issue. I need output from the remote command execution with or without pwd. – Elangovan Manickam Jul 04 '14 at 10:42

2 Answers2

4

This indicates that there is a problem with making the SSH connection. Run the commands with -v to see what SSH does behind right before it hangs.

Do it with the working account to see what it would look like if it succeeds.

Repeat the option to see more (i.e. -v -v -v -v will give you almost every bit that is exchanged).

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • 1
    I tried your suggestion by using `-v`. The last statement where it gets stuck is _debug1: Sending command: date_ . In the working account the execution continues and prints the date. – Elangovan Manickam Jul 04 '14 at 10:30
  • Then something is wrong with the `date` command. What do you get for `which date`? – Aaron Digulla Jul 04 '14 at 10:41
  • It gives me `/bin/date`. If I split the remote command into two steps i.e first do ssh and then execute `date` command in the logged in session then it is working. So I think date command is working fine. – Elangovan Manickam Jul 04 '14 at 10:45
  • Try `ssh -v -v -v` just to make sure it can send the command successfully and hangs waiting for the result. Then try `ssh /bin/date` and `ssh /bin/bash -x /bin/date`. – Aaron Digulla Jul 04 '14 at 11:33
3

My problem Resolved !!! Thanks for @Aaron for helping me in debugging it.

I was going through this link and found that exec line from login profile making such issue each time when I do ssh.

From .cshrc file I removed the following line. That solved my problem.

exec bash

Thanks for everyone showing interest to solve this issue.

Community
  • 1
  • 1
Elangovan Manickam
  • 413
  • 1
  • 5
  • 14