Remote command execution via ssh does not work
I’m trying to execute commands on a remote server using ssh. The command is as follows
ssh machine -l user "ls"
This command got stuck in the middle, and in the end we had to pause it.
However, executing the command
ssh machine -l user works fine, and this command lets us connect to the remote machine.
Can anyone help find out the root cause of LS not working with ssh on the remote server.
Edit 1: This is the output after using the -v switch in 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
the Sending command: ls terminal stuck.
I suspect one of two things is happening. First, the SSH server may be set up to launch a specific command for the user, regardless of what command you ask to run. If the user is restricted to running SFTP in the usual manner, you see this behavior, for example. There are two ways to set this up:
- The remote server’s in the sshd configuration file ForceCommand directive
- The remote user’s directive authorized_keys the key being used by the file.
The easiest way to check this is to log in to the remote server and check both files. Alternatively, you can start one of the ssh sessions, let it hang, and then run “ps” on the remote server to see the actual process being run for the user in question.
Another possibility is that the remote user has a line in his .bashrc or other shell startup script that introduces wait or wait for you to type. Again, you should launch one of these ssh sessions, let it hang, and then run “ps” on the remote server to see the actual process being run for the user.