Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I often SSH into a cluster node for work and after processing want to pull several results back to my local machine for analysis. Typically, to do this I use a local shell to scp from the server, but this requires a lot of path manipulation. I'd prefer to use a syntax like interactive FTP and just 'pull' files from the server to my local pwd.

Another possible solution might be to have some way to automatically set up my client computer as an ssh alias so that something like

scp results home:~/results

would work as expected.

Is there any obscure SSH trick that'll do this for me?


Working from grawity's answer, a complete solution in config files is something like

local .ssh/config:

Host ex
    HostName ssh.example.com
    RemoteForward 10101 localhost:22

ssh.example.com .ssh/config:

Host home
    HostName localhost
    Port 10101

which lets me do commands exactly like

scp results home:

transferring the file results to my home machine.

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

I'd prefer to use a syntax like interactive FTP and just 'pull' files from the server to my local pwd.

Use sftp.

(Hint: If you cannot or do not want to open a new window, you can suspend the SSH connection by pressing Enter, ~, CtrlZ, transfer your files, and resume SSH with fg.)

Another possible solution might be to have some way to automatically set up my client computer as an ssh alias

There are a few ways.

  • Static alias for ssh and scp – add this to your ~/.ssh/config:

    Host home
        # If you don't have a domain name, check out DynDNS...
        # ...or just use your IP address.
        Hostname homepc.somedomain.tld
    
        # If necessary, uncomment:
        #User john
        #Port 1234
    

    Use:

    scp foo home:
    

    (If you don't provide a path after :, the file will go to your home directory.)

  • Use the SSH_CLIENT environment variable.

    export client=${SSH_CLIENT%% *}
    if [[ $client == *:* ]]; then
        client="[$client]"
    fi
    

    Put that in ~/.profile or ~/.bash_profile or wherever you want, then use $client when you need your own address.

    scp foo "$client:"
    
  • Mix both.

    ~/.ssh/config:

    Host client
        ProxyCommand ~/bin/reverse-connect %p
    

    ~/bin/reverse-connect:

    #!/bin/sh
    if [[ $SSH_CLIENT ]]; then
        client=${SSH_CLIENT%% *}
    else
        echo "I don't know your address." >&2
        exit 1
    fi
    if [[ $client == *:* ]]; then
        client="[$client]"
    fi
    
    port=${1:-22}
    
    exec socat - "tcp:$client:$port"
    

    Use:

    scp foo client:
    
share|improve this answer
    
SSH_CLIENT is almost perfect! What about if I'm behind a router, though? It's common since I'm connecting from a laptop. I had been imagining some sort of reverse ssh tunneling scheme, but I don't know how to set that up. –  J. Abrahamson Feb 13 '11 at 12:39
    
@tel: Method 1, port forwarding: Pick any port and forward it to port 22/tcp on your computer. Tell the same port to scp when copying files. –  grawity Feb 13 '11 at 13:14
    
@tel: Method 2, "reverse forwarding" with SSH: ssh -R 2345:localhost:22 will make your computer reachable as localhost port 2345 from the remote server. –  grawity Feb 13 '11 at 13:15
add comment

Have you tried sshfs ? It's easy as

> sshfs hostname: mountpoint

and

fusermount -u mountpoint

and then you can use all the classic and basic file manipulation commands.

http://en.wikipedia.org/wiki/SSHFS

http://fuse.sourceforge.net/sshfs.html

share|improve this answer
    
sshfs is fantastic. Much more usable than sftp and gftp. –  new123456 Mar 29 '12 at 0:53
add comment

You could use scp from your local host. Use a command like scp server:file ..

Your other options include sftp and sshfs as already noted.

For all of these I would use authorized keys. It is more secure to password protect your key. I use ssh-agent to serve the keys to ssh as needed. The command ssh-add will prompt you for your key's password and load the key into ssh-agent.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.