I am trying to copy some files, from a computer that is located elsewhere.
Machine A connect to remote Machine B via ssh, pass a script, and this script will have to copy files from Machine B to Machine A.
I can't find a way to make this work, without open another connection to copy the files (tried rsync and scp). I would like to use the same ssh connection used to copy the script on Machine B, since I have keys that allow me to connect without password. This is to automate a process, so I need it to run without intervention.
What is the correct syntax to copy from remote machine B on machine A, using the ssh connection already open?
I can open a connection from Machine A to Machine B and run from Machine A the rsync command, but what I want is the other way: send from Machine B to Machine A, after that I ssh in Machine B.
I suspect the solution is easier than what I am thinking, but I can't really see it.
If by writing a script your goal is to avoid having to authenticate again, consider using the ControlMaster feature of ssh, which will allow further ssh sessions to authenticate over the existing one:
http://puppetlabs.com/blog/speed-up-ssh-by-reusing-connections
Then you could use scp, sftp or rsync over ssh to retrieve the files from the remote machine as Kenster suggests.
Related
I have an expect script which runs ssh and eventually results in a shell. Is it possible to run this script whenever someone ssh's to the matching machine, instead of just using ssh? (ideally by setting some config in ~/.ssh/config)
I'd prefer not to create an alias/script for ssh to check what the host is, then run the appropriate shell.
I am fairly new to ssh and still learning it. Recently I have made a tunnel connection with an ssh host and managed to successfully transfer data/files from my machine to the server with the command: scp file.extension user#hostIP:/directory/directory.
While this was successful, I am kinda struggling to reverse it, sending data/files from the server to the client. How would one go about completing that? Do I need to make some changes to ssh_config or just CLI commands are enough?
You need to change the order:
scp user#hostIP:/directory/directory file.extension
that's accomplishing the invert operation, off course, assuming that the address is correct, the file exists and you have the necessary privileges.
I'm working on a project that requires me to run my code on a remote Unix server, that is not available to connect to directly (you first have to log in to the "gate" node and then to this server).
What's really bad is that they disabled key authentication, so each time I need to ssh into it, I have to type in my password twice. It's really annoying and I wonder what's the best way to transfer my local modifications of source files to this server, compile and run them without having to provide those passwords so many times.
I have no sudo access to any of those servers (neither to this "gate", nor to this target server). Any ideas on how to make the whole process more efficient?
EDIT: Martin Prikryl provided a great answer below, but it's suitable for Windows and I'm on a Mac :) I guess it might be a good thing to have it documented here also for *NIX systems.
You are looking for SSH tunneling.
WinSCP SFTP client supports one-hop SSH tunneling natively.
See the Tunnel page on WinSCP Advanced Site Settings dialog.
I assume that after you transfer the file, you need to open SSH terminal to compile the file.
You may be able to make use of WinSCP Console window for that step.
Alternatively, if you need/want to use a real SSH terminal client, make use of an existing SSH tunnel, created by WinSCP, and connect with PuTTY (or any other SSH client) over it.
In the Local tunnel port of WinSCP Tunnel page, select a fixed port number (instead of the default Autoselect). In PuTTY enter "localhost" to Host Name and the selected port in Port.
(I'm the author of WinSCP)
Currently I have a machine setup to send files it generates via a script to a remote server for file storage, where each user has their own folder on the remote server, which they can then SFTP into to get their files.
Currently, when the machine generating the files copies them over, via SCP, it prompts for a password for the user it's sending to.
What I would like to be able to do is enable the machine to send the files to the individual user accounts without prompting for a password. I've read a few ways to do this by creating ssh keys in each user's accounts. However, due to the volume of users, I was wondering if there was a way to enable machine1 to be able to scp files to any user account on the remote file server without prompting for a password each time?
You can set up host-based authentication on the target host to accept connections from the source host. This will work for any kind of SSH access, not just SCP. If you want to limit users to just SCP, there are ways to do that. see this question for example.
Try something like:
sshpass -p scp -o StrictHostKeyChecking=no source dest
I have used it on some linux machine. Don't know if it always work (last day i tried on osX and it refused cause it will break ssh security)
BTW you have to install sshpass
I want to create a service that will allow me to display documents and media (think PDF and JPEG) that are stored in the filesystem of a remote server to which I connect by ssh. X11 forwarding doesn't cut it because it's too slow. Instead I want to design a protocol that will copy files from the remote system on demand, then display them.
My question is twofold:
How do I acquire a port on the remote machine? Since I may have multiple connections going, I cannot simply use a single well-known port—I will have to allocate a port dynamically.
Once I have my port, how do I communicate it to the display applications on the remote machine? SSH X11 forwarding communicates by setting the DISPLAY environment variable, and agent forwarding communicates by setting the SSH_AUTH_SOCK environment variable. Perhaps I can do something creative with a remote command?
I welcome any ideas.
Do you really need a remote port? If you can ssh into the remote machine, why not run a command and send data back over the ssh command, like rsync, Mercurial, Git, and so on do. SSH can provide an 8-bit clean connection, so it's just like having a socket connection.
To be clear, what i am suggesting is:
SSH from origin to the destination
In the SSH session, run a command on the destination that writes data to its standard output
The standard output is sent over the SSH connection from destination to origin
Collect the data that emerges from the standard output of SSH on the origin machine
There is then no need to open a particular port on either the origin or the destination.
Indeed, if what you really want is "a protocol that will copy files from the remote system on demand", how about SCP, SFTP, or rsync over SSH?