Executing command on remote using ssh doesn't work

I am trying to execute a command on a remote server using ssh. Command matters

ssh machine -l user "ls"

      

This command is stuck in between and we finally need to pause it.

But executing the command ssh machine -l user

works great and this command allows you to connect to the remote machine.

Can someone please help in getting the main reason why ls on the remote server is not working with ssh.

EDIT 1: Here is the output after using the -v switch with SSH

debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending command: ls

      

After printing, the Sending command: ls

terminal shuts down.

+3


source to share


2 answers


I suspect one of two things is happening. First of all, the ssh server can be configured to run a specific command for the user, no matter what command you asked to run. You will see this behavior if the user was restricted to run SFTP in the usual way . This can be done in two ways:



The easiest way to test this is to log into the remote server and check two files. Alternatively, you can start one of these ssh sessions, let it hang, and then run "ps" on the remote server to see what actual processes are running for a given user.

Another possibility is for the remote user to have a line in their .bashrc or other shell script startup that enters wait or expects you to type something. Again, you have to start one of these ssh sessions, let it hang, and then run "ps" on the remote server to see what actual processes are running for the user.

+3


source


Questions: Does the problem occur on the command line or in the script? Will you be prompted for your password? Is there a way out? If yes: submit it here.

And try

ssh -v user@host "ls"

or

ssh -v -l user host "ls"

and you get an extra output. You can use the -v option up to 3 times for more verbosity.

ssh -vvvl user host "ls"

EDIT:

If I had to debug this I would do the following:

  • go to the target machine you want to "ssh" to.
  • login with the same user you tried with ssh
  • enter the command "ls"

This is not an easy thing to do, but "ls" is not necessarily what you expect. At the command prompt on the target computer, try



which ls

and then use the fully qualified output for your ssh call like:

ssh machine -l user "/bin/ls"

Remember that when issuing a command via ssh, you do not automatically have the same path as when you log in normally.

Finally, check your log files on the target machine. They are usually found in / var / log (at least under debian).

EDIT2:

On Linux machines, I sometimes had a problem with hanging the ls command without output. This happened to me when there were filesystems in the directory that were somehow "invalid". For example, if there was an invalid mount of android mtpfs, the ls command couldn't handle it and hung up.

So try "ls" a different directory like

ssh host -l user "ls /tmp"

If that works, check on the command line to see if there is a directory or file with some invalid state that is causing the ls command to fail.

0


source







All Articles