Run `make` and Retrieve Binary from Remote Host Without SSHing Twice – How to Guide

linuxscpsftpssh

I'm working on a project for which I don't have the toolchain configured on my own machine and I'm thus developing remotely. My workflow right now looks as follows:

  • open the remote project directory in my file manager using sftp
  • edit some files
  • run make remote, which connects to the remote machine via ssh and runs make there:

    ssh $(HOST) cd $(DIRECTORY) \; make

  • run make get, which transfers the binary via scp:

    scp $(HOST):$(DIRECTORY)/build/$(FILE) .

  • test the binary and repeat

The problem is, the remote machine only does password authentication, so I have to enter the password twice in each cycle. Can't I build and download in the same ssh session?

Best Answer

I think SSH session sharing would be useful in this situation. It allows you to open multiple sessions over a single connection so that you only have to enter your password once. In your .ssh/config:

Host *
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p

So you could open one terminal, SSH into your server, and run your editor. Then you could open another terminal, SSH into the same server using the shared connection, and run make and scp from there. More info:

Related Question