I am trying to transfer a directory from a remote server(CentOS) to my local machine(Ubuntu) over ssh. There are two users : A and B. User A can ssh into remote server and has sudo access. User B owns a directory in remote server.
To transfer a directory owned by User B as User A, sudo needs to be used.
Currently for transferring a file (from remote to local) this is what I am using :
ssh -tt userA@remote_host 'stty raw -echo; sudo cat /path/to/remote/file/owned/by/userB' > /path/to/local/file
To transfer a directory I have tried the tar approach,
ssh -tt userA@remote_host 'stty raw -echo; sudo tar -C /path/to/remote/directory/owned/by/userB/ -czf - .' | tar -C /path/lo/local/directory -xzf -
However on the local system I get this error :
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
What am I doing wrong?
-t
option, I get this error :sudo: sorry, you must have a tty to run sudo
ssh
with separate stdin, stdout, stderr AND tty.