Solved

Secure tunnel using SSH to a backend FTP server

Posted on 2011-03-02
7
715 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 500 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 7

Assisted Solution

by:rodness
rodness earned 500 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 500 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Finder.   The ubiquitous, built-in feature of the Mac OS X platform, that never sleeps, can help get to any destination within your Mac OS X volume, allows you to customize your desktop, files and folders and so much more. As one of the primary…
If you are using Mac OS X and have a large number of login items set up in accounts, under system preferences, you may find that your computer is sluggish and unresponsive during startup until everything is done launching. Another problem that a…
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 …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

911 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now