5

I got a server A, it has three users on it. I need to download a folder's 70 gigs of content into server B. The server only has 90 gigs of space, so compressing, then transferring isn't an option. In my experience rsync is extremely slow 10x slower than other methods.

I have always used

ssh user@ip "tar zc -C /home/minecraft/multicraft/servers/server2 ." | tar zx

This command is amazing because it opens up a pipe and directly downloads everything you want, at maximum speed. It doesn't slow down from tiny files like rsync does. I've used this to transfer stuff in the fast and it's so quick that the 100 mbps upload is the bottleneck.

Anyway but server A has a user I log into, it also has sudo -i, and finally there is also minecraft, the user files are actually under. The user isn't an actual user, it's just the placeholder for the files for security purposes. I can't login into this user.

So what I must do is, ssh from server B into server A, with one command sudo into root, provide root password, and then perform my usual

ssh user@ip "tar zc -C /home/minecraft/multicraft/servers/server2 ." | tar zx

Please help me almighty computer wizards.

10
  • Did you try "scp"? Maybe it is more suitable for what you want.
    – migrc
    Oct 19, 2015 at 10:23
  • oh, i'm not even sure what that is. Can you give me an example of what to type? I use like winscp but i do it to download files through ssh onto my personal computer and that process is usually very slow.
    – Web Master
    Oct 19, 2015 at 10:28
  • just tried scp scp: /home/minecraft/multicraft/servers/server2: Permission denied
    – Web Master
    Oct 19, 2015 at 10:35
  • to copy file1 from local machine to remote machine: "scp file1 user@host:path". Inverse : "scp user@host:file1 path"
    – migrc
    Oct 19, 2015 at 11:10
  • but the problem is, the user i scp into, doesn't have access to the file. I have to scp or ssh into the remote machine, then I must sudo into root, only then can I download the file. in our example user, doesn't have access to file1
    – Web Master
    Oct 19, 2015 at 11:13

2 Answers 2

9

You got the error message sudo: no tty present because ssh does not automatically allocate a tty device when you are in non-interactive mode. ie you have specified a command to run on the remote system.

You can force ssh to allocate a tty device using the -t option.

ssh -t user@ip "sudo tar zc -C /home/minecraft/multicraft/servers/server2 ." | tar zx
1
  • haven't tried it, but ey mang, ill still vote you up XD
    – Web Master
    Oct 19, 2015 at 13:36
4

You can use the sudo inside your ssh command. For sudo password prompt, you can pass the password in plain text using the -S switch:

ssh user@ip "echo mypassword | sudo -S tar zc -C /home/minecraft/multicraft/servers/server2 ." | tar zx

Another method, which I am not elaborating much is using expect. You can look into that too.

6
  • it is doing something!@!@
    – Web Master
    Oct 19, 2015 at 12:00
  • Glad it helped :)
    – shivams
    Oct 19, 2015 at 12:00
  • YUP! i think it worked! disk usage going up like crazy
    – Web Master
    Oct 19, 2015 at 12:01
  • 2
    The downside of this method is that it adds your password to your shell's history. Congratulations, everyone who has access to your server can easily read your password. The other answer (the one that suggests ssh -t) is much safer. Oct 19, 2015 at 13:57
  • 1
    @syss yes, as can anyone who can read over your shoulder. Point is mainly that entering a password on the command line is unsafe, because there are ways of recovering it then. The exact manner in which it is recovered doesn't really matter... Oct 19, 2015 at 15:03

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.