how to scp to host connected on a wifi?
Solution 1
I would continue to use your computer as a the local machine and put the wildcard on the remote host side by running the following command on your MAC:
mac> scp [email protected]:remote/folder/file* local/folder
If you really want to log in to your machine from the remote host here is a brief guide.
The wi-fi connection you are on is likely over a local area network (LAN) and the remote host is probably operating over the internet as a whole which, from your Mac's perspective, is the wide area network (WAN). The IP address you are seeing with ifconfig
is almost certainly your LAN address and not the WAN address that the remote host needs. If you open up your terminal and run curl http://myip.dnsomatic.com; echo;
you should be able to see the WAN IP address of your LAN. This will only get you to your LAN's router though, you will likely need to explicitly tell the router to forward ssh traffic (on port 22 by default) to your particular computer using the LAN IP address of your Mac that you obtained with the ifconfig
command. As Mark Plotnick mentioned you will also need to be sure that SSH is turned on on your Mac (system preferences -> sharing -> remote login & file sharing) and that there are no firewalls between you and the remote servers blocking incoming traffic on port 22. Lastly, be very careful opening your computer up to the internet like this and turning on remote log in. It's not very safe to do this over the default port 22, especially without configuring some more advanced security options. At the very least make sure your administrative users all have strong passwords and I would turn off remote login and file sharing whenever you don't need it.
Wikipedia had nice descriptions of LAN and WAN that might be worth looking over.
Solution 2
Ok, first of all the linux host MUST have the SSH service on.
i.e.(ubuntu)
host$ /etc/inist.d/ssh status
* sshd is running
Then you MUST have to have connection to the SSH port of the host
mac$ telnet <IP.of.the.host> 22
Trying X.X.X.X ...
Connected to X.X.X.X
Escape Character is
SSH-X.X-OpenSSH_X.X
Then you could be able to scp FROM/TO the host
scp -P <PORT> <source> <destination>
i.e.
scp -P 22 [email protected]:/home/user /home/user
If you don't have the SSH service running or permission to ssh the host, you wouldn't be able to make any kind of ssh connection
Remember, scp makes the connection though SSH service
Related videos on Youtube
![Walter](https://i.stack.imgur.com/2g9CZ.jpg?s=256&g=1)
Walter
programming numerical algorithms for astrophysical applications.
Updated on September 18, 2022Comments
-
Walter almost 2 years
I have my MAC on a wifi and am connected via
ssh
to a linux host. I want to copy some files from the linux host over to my MAC. I know, I can simply runscp
on the mac to fetch each file viamac> scp [email protected]:remote/folder/file local/folder
but I cannot do that with one command for many files (I could
tar
them first into an archive using thessh
connection and then ship the archive in one go, but I want to avoid this). So instead, I want to send all the files from the remote host (to which I'm connected by ssh) via (note the usage of a wildcard)host> scp remote/folder/files* [email protected]:local/folder
but what is the appropriate
mac.some.where
here, i.e. how can I obtain that, when my MAC is connected to some wireless? I tried the (numerical) IP address (obtained byifconfig
), but to no avail.-
Mark Plotnick almost 10 years
scp remote/folder/files* [email protected]:local/folder
ought to work, where W.X.Y.Z is the IP address of the Mac, unless there's a firewall blocking ssh, or the Mac is behind a router that's using NAT, or there's no ssh daemon running on the Mac. What error message do you get? Can you ping the Mac from the Linux host? -
Walter almost 10 yearsNo that didn't work (error:
ssh: connect to host ... port 22: Connection refused
). I tried to ping (using the IP address, but ping simply hangs). -
Mark Plotnick almost 10 yearsConnection refused usually means the remote system is reachable but there's no daemon listening on that particular TCP port. @vaaaal has the two logical options: you can enable the ssh server on the Mac, or you can pull the files over by typing scp on the Mac. (I'd put quotes around the filename that ends in * so that the Mac shell doesn't try to expand it.)
-
-
Walter almost 10 yearsYou cannot use the wildcard for a remote file.
-
Walter almost 10 yearsAs I've said, I ssh from the mac to the remote host.
-
tachomi almost 10 yearsOk, then telnet remote host ip to ssh port to see if you have connection
-
Reed Espinosa almost 10 yearsI tested it on from my machine (OSX-10.9) on two different remote hosts and it worked perfectly. The remote servers were running OSX-10.6 and Ubuntu 10.04.4 LTS with sshd versions OpenSSH_6.2p2 and OpenSSH_5.3p1, respectively. Are you sure your system doesn't support it?
-
Walter about 6 yearsThis may have to do with the local system exploding the wildcard locally instead of sending it over. How can that be avoided?