I have two Solaris servers. On server1 I have a file, archive.tar.gz. I need to extract it using ssh to server2.

So, I write the commands:

ssh server2 < archive.tar.gz | gunzip -c | tar -xf - -C /home/

But I got an error:

Pseudo-terminal will not be allocated because stdin is not a terminal.

How to copy the file correctly?

  • Are you asking how you can login to server1 and extract the archive.tar.gz file and send it via ssh to server2? – slm Sep 11 '13 at 6:44

I believe you could do something like this:

$ cat archive.tar.gz | ssh server2 "tar zxvf -"

If you need to control the directory where it gets extracted to on server2:

$ cat archive.tar.gz | ssh server2 "cd /path/to/dir; tar zxvf -"


Given you're on Solaris your version of tar is likely to not include any of the compression features that GNU tar offers. Fear not you can still do this command, we just need to decompose the cat archive.tar.gz into a command that can first uncompress the tarball.

Something like this should do:

$ cat archive.tar.gz | ssh server2 "(cd /some/dir; gunzip | tar xf -)"

Or this:

$ gzip -dc < sample.tar.gz | ssh server2 "cd /path/to/dir; tar xvf -"

Or this:

$ gunzip sample.tar.gz | ssh server2 " cd /path/to/dir; tar xvf -"
  • Solaris tar does not understand the x flag. So either use gtar (GNU tar) if it's installed, or better use tar and gunzip. – Marco Sep 11 '13 at 7:32
  • @Marco - thanks I completely forgot that those switches aren't present in Solaris' version of tar, let me reformulate it. – slm Sep 11 '13 at 7:34
  • @Marco - see updates. – slm Sep 11 '13 at 7:43
  • 1
    Why do you decompress before ssh? This seems better IMO: cat archive.tar.gz | ssh server2 "(cd /some/dir; gunzip; tar xf -)" – Marco Sep 11 '13 at 7:48
  • Every Solaris version ships with g(un)zip, zip support is just not compiled into tar. – Marco Sep 11 '13 at 7:50
ssh server2 < archive.tar.gz

You aren't passing any command to ssh, so it executes a shell on the remote side. The contents of archive.tar.gz are passed to that shell on its standard input, so it tries to parse it as a shell script. Hilarity may ensue, or not, depending on the content of the file.

It isn't clear in your description where you're running these commands. If you're on server1, have archive.tar.gz on server1, and want to extract the archive on server2, then pipe the archive to server2 and run the extraction command there.

<archive.tar.gz ssh server2 'cd /home && gunzip | tar -xf -'

Alternatively, log in to server2, mount the filesystem of server1 over sshfs, and unpack the archive just like you'd unpack a local file.

mkdir /tmp/server1
sshfs server1:/ /tmp/server1
cd /home
gunzip </tmp/server1/path/to/archive.tar.gz | tar -xf -
fusermount -u /tmp/server1
  • wow, sshfs is awesome! – knocte Jun 2 '16 at 14:19

You can expand the archive into a specific existing directory without using cd command like this:

$ cat archive.tar.gz | ssh server2 "tar zxvf - -C /path/to/dir"

If you don't know if the directory exits you can use this:

$ cat archive.tar.gz | ssh server2 "mkdir -p /path/to/dir && tar zxvf - -C /path/to/dir"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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