MoonPoint Support Logo

 

Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
May
Sun Mon Tue Wed Thu Fri Sat
26
       
2016
Months
May


Thu, May 26, 2016 11:53 pm

Running a command on a remote system using SSH

The Secure Shell (SSH) protocol allows you to interactively log into remote systems. Once logged into a remote system, you have a shell prompt where you can enter commands on the remote system. But you can use an SSH client to execute a command on a remote system without logging into that system and obtaining a shell prompt on the remote system. E.g., if you wanted to get a command line interface (CLI) on the remote system, you might enter a command similar to the following one:
$ ssh jdoe@example.com

But, if you just were logging in to enter one command, say you wanted to find the hardware platform of the remote system using the uname command uname --hardware-platform, you could simply append that command to the end of the above ssh command you would have used to log into the remote system. E.g.:

$ ssh jdoe@example.com uname --hardware-platform
jdoe@example.com's password: 
x86_64
$ uname --hardware-platform
i386

In the example above, issuing the same command on the local system, i.e., the one on which the SSH command is being issued shows that the result returned when the uname command was issued at the end of the ssh command line returned a result from the remote system.

You may even be able to use a text-based editor, such as the vi editor, though you may see error messages like the ones below:

$ ssh jdoe@example.com vi temp.txt
jdoe@example.com's password: 
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal

When you enter an ssh command in the form ssh user@host the remote system allocates a pseudo-tty (PTY), a software abstraction used to handle keyboard input and screen output. However, if you request SSH to run a command on the remote server by appending that command after ssh user@host, then no interactive terminal session is required and a PTY is not allocated, so you see the error messages when you use a screen-based program intended for use with a terminal, such as the vi editor.

For such cases you should inclde the -t option to the SSH command.

-t Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.

E.g.:

$ ssh jdoe@example.com -t vi temp.txt

[/network/ssh] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo