Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Secure tunnel using SSH to a backend FTP server

Posted on 2011-03-02
7
Medium Priority
?
787 Views
Last Modified: 2012-05-11
Hi,

Is it possible to do this using SSH to the Linux Server so that the FTP Server is exposed on my Mac through the SSH tunnel?

Mac > Internet > Linux Server > Internal Network > FTP Server

Basically, I want to connect to the FTP server directly from my Mac (note that the FTP server is NOT on the front end Linux server)

Normally, I would do
ssh user@server.net
ftp ftp.internal.lan


Thanks
BT
0
Comment
Question by:brothertom
  • 4
  • 3
7 Comments
 

Author Comment

by:brothertom
ID: 35016313
I'm guessing we would also need to make changes to the iptables on the Linux Server to specific a port, say 4444 to port 23 on ftp.internal.lan
0
 
LVL 7

Accepted Solution

by:
rodness earned 2000 total points
ID: 35017524
You can do this with SSH port forwarding:

sudo ssh -L 21:ftpserver.net:21 user@server.net
ftp localhost

Open in new window


This will connect you via ssh to user@server.net.  It will open port 21 (ftp) on the local system and forward connections to port 21 (ftp) on the ftpserver.  It needs to be run as root (sudo) because port 21 is privileged, and only root can open it.

Then you just ftp (or use cyberduck or whatever) with localhost as the address, and the connection is automatically forwarded to the desired computer.  Note that OTHER computers CANNOT connect to port 21 on your machine... you can only connect locally, for security reasons.  So you can't use this to just create a wide open tunnel for anyone hitting your machine through to the ftp server.  (This is a good thing.)

Alternately, if you don't want to use sudo:

ssh -L 4444:ftpserver.net:21 user@server.net
ftp -P 4444 localhost

Open in new window

This will open port 4444 locally instead, which doesn't require root (sudo) privilege.  You just need to specify that port for the ftp command.

0
 

Author Comment

by:brothertom
ID: 35018039
Thanks for your reply.  Your solution will allow FTP on the server via SSH, but the FTP server is actually hosted on a machine behind the front end server.

I think your technique will work, but I need to figure out how to direct the incoming FTP traffic (over SSH) to the backend ftp server.

Thoughts?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 7

Assisted Solution

by:rodness
rodness earned 2000 total points
ID: 35018190
No, this enables a local port (on your Mac) to be redirected THROUGH the ssh server to the FTP server.  This is exactly what you asked for, to use the ssh server to expose FTP so that you can connect directly to the FTP server from your Mac.

This is because of the argument to -L:  21:ftpserver:21

The first argument is the local port (Mac). The second is the remote server, which is the FTP server, and finally the remote port.

Give it a try. :)
0
 

Author Comment

by:brothertom
ID: 35018714
OK, I get it - tried connection to ftp.microsoft.com

Get to login and password, but when doing ls, I get connection refused.  
Tried a couple of servers but same.  
Is port only port 21 used, or does port 20? need to be included somehow?
Got a vague memory of FTP using more than one port.

BT


ftp 127.0.0.1
Connected to 127.0.0.1.
220 Microsoft FTP Service
Name (127.0.0.1:user1): anonymous
331 Anonymous access allowed, send identity (e-mail name) as password.
Password:
230-Welcome to FTP.MICROSOFT.COM. Also visit http://www.microsoft.com/downloads.
230 User logged in.
Remote system type is Windows_NT.
ftp> ls
229 Entering Extended Passive Mode (|||13744|)
ftp: Can't connect to `127.0.0.1': Connection refused
200 EPRT command successful.
150 Opening ASCII mode data connection.
0
 
LVL 7

Assisted Solution

by:rodness
rodness earned 2000 total points
ID: 35019179
Dammit.  You're right, I forgot about the passive connections.  While you can supply multiple -L commands to forward multiple ports, it's hard to predict the passive port that the server is going to tell you to connect on.  (In your case, 13744, which wasn't open on the local machine.)

Is it an option to run sshd on the ftp server?  Then you can simply forward port 22 instead of 21, and use sftp instead of ftp.

From googling, it doesn't look like there's an easy answer to this.  It's kind of why sftp has replaced ftp.... ftp over ssh tunnels is just not easy.  sftp was designed for this.


0
 

Author Comment

by:brothertom
ID: 35027026
I think the backend FTP server is just a dumb ftp box, but I'll see if it supports sftp (therefore sshd) and try that.

Thanks
BT
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The error "There was an error performing the update" occurred on a Mac OS X client workstation running  Symantec AntiVirus for Mac (http://www.symantec.com/business/products/purchasing.jsp?pcid=pcat_security&pvid=825_1) - the Enterprise product vers…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question