Best Way To Transfer Files?

Bernie Hoefer LUG-Member at TheMoreIKnow.info
Sun Jan 22 04:34:08 EST 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

     I've got a question for the CINLUG hive-mind:  I've got 2 servers;
let's call them $SRC_SERVER and $DST_SERVER.  They are each on networks
separated by a firewall, so I cannot SSH directly from one to the other.
 Additionally, their SSH servers are configured to block logging in as
root.  My regular account on both servers has root-sudo access, however.
     I want to transfer a root-owned, only-root-can-read file, keeping
file ownership, permissions & the modification date from $SRC_SERVER to
$DST_SERVER.  Luckily, I have a 3rd server on a network that has SSH
access to both servers.
     To transfer the file, I'll obviously need to use my root-sudo
access on $SRC_SERVER to access the file (since it is readable only by
root) and I'll also need to use my root-sudo access on $DST_SERVER since
I need to create that file with root-ownership & permissions.  I came up
with using SSH & tar (since it preserves ownerships, permissions &
dates) from the 3rd server to accomplish this task:

ssh -q $SRC_SERVER "sudo tar -C /path/to/source -cpf - filename" | \
ssh -qtt $DST_SERVER "sudo tar -C /path/to/destination -xvpf -"

     That works, though I get a "tcgetattr: Invalid argument" warning.
A commenter on this web page[1] says this warning can be ignored.  But
I'd like to know from you all:  is there a better way to do this?  Is
there a way I should do this to get rid of the "tcgetattr: Invalid
argument" warning?

     Secondly, I wonder about my double use of "-t" (force pseudo-tty
allocation) in my 2nd SSH command.  I have to use that SSH option
because of my use of the sudo command; /etc/sudoers on both servers has
"requiretty" set in it.  But why do I have to double-force it?  Why
doesn't just 1 "-t" work?  Examples:


$ ssh -q $SRC_SERVER "sudo tar -C /path/to/source -cpf - filename" | \
ssh -q $DST_SERVER "sudo tar -C /path/to/destination -xvpf -"
sudo: sorry, you must have a tty to run sudo

$ ssh -q $SRC_SERVER "sudo tar -C /path/to/source -cpf - filename" | \
ssh -qt $DST_SERVER "sudo tar -C /path/to/destination -xvpf -"
Pseudo-terminal will not be allocated because stdin is not a terminal.
sudo: sorry, you must have a tty to run sudo


     What's also confusing to me is that even though $SRC_SERVER's
/etc/sudoers has the "requiretty" set, I cannot use the "-t" option on
the 1st SSH command.  I discovered that when I use it, my command
produces a tarball with a carriage return (ASCII 0x0d) character
inserted before each line feed (ASCII 0x0a) character.  Thus, the
contents of the tarball are not an exact duplicate of the source file.
     Thanks for any light you all can shed on this!


[1]<http://dbaspot.com/shell/402774-redirecting-stdin-file-requiring-parameters-2.html>
   "The "tcgetattr: Invalid argument" is generated by ssh, when the
   tcgetattr(3) function call fails with errno==EINVAL.
   The failure is self-evident, as the redirected stdin is not a terminal
   (ssh: "Pseudo-terminal will not be allocated because
   stdin is not a terminal."). As long as the termios functionality is not
   used by the shell script, no harm will be done.

- -- 
Bernie Hoefer
PGP e-mail is welcome!  Get my 1024 bit signature key from:
<http://pgpkeys.mit.edu:11371/pks/lookup?op=get&search=0x446A6F93>.
"The more I know, the more I realize how much I do not understand."

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8b2AgACgkQckGmqURqb5PQ2gCffGfqfXuNVrllO3ddLrmE5Sy7
xNsAoJsQDbew1r7K5W5QoRQ47K1VGrRs
=aHR6
-----END PGP SIGNATURE-----


More information about the cinlug mailing list