sabato 2 maggio 2015

Edit a remote file via ssh

ssh is mainly used to securely remote login to another computer.
It can also be used to issue commands on a remote machine without actually logging in. Thus, you may as well edit a remote file using vi. The syntax would be

ssh user@host 'vi filename'

Unfortunately you'll get the following message

Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal

You can quickly resolve the problem adding -t option to ssh

ssh -t user@host 'vi filename'

Here's what man ssh tells about -t option


  • -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.