Solved

Secure tunnel using SSH to a backend FTP server

Posted on 2011-03-02
7
712 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 7

Assisted Solution

by:rodness
rodness earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Deploystudio is a system which can be used to deploy OSX clients and servers within the small/medium or large business environments. The system is built ontop of the OSX Server NetBoot system and uses images & workflows as its core assets. Although …
Deploystudio is a system which can be used to deploy OSX clients and servers within the small/medium or large business environments. The system is built onto of the OSX Server NetBoot system and uses images & workflows as its core assets. While work…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

12 Experts available now in Live!

Get 1:1 Help Now