Why doesn't FTP work through my ssh tunnel?

Computer A (assumed that ip is ftp the host

Connected to
220 ftp.debian.org FTP server
Name ( anonymous
331 Please specify the password.
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.

Computer B (my local pc) can not ftp the host
Let’s build a ssh tunnel with ssh command this way:

ssh -L -f -N localhost:2121:   root@

The ssh tunnel between my local pc and Computer A ( was connected after password to login into
Then to input the command on my local pc console:

ftp  localhost:2121
ftp: localhost:2121: Name or service not known

What is the matter with my ssh tunnel?

Think to chexum, the right ftp command is ftp localhost 2121
But new problem.
enter image description here

Asked By: showkey


Your approach is not taking in account that contrary to other common protocols, FTP uses both port 20 and port 21 over TCP by default.

The term passive refers that the protocol is slightly better behaved than the initial implementations.

Here is a link:


Port 20/TCP is used for data, and port 21/TCP for commands.

In Unix, also privileged ports < 1024, only can be bound by root.

So either you do:

sudo ssh -f -N -L 20: -L 21: user@

This way you do not give any extra port, and only use it with

ftp -p localhost

or if you do not have root:

ssh -f -N -L 2120: -L 2121: user@

and then use:

ftp -p -P 2121 localhost 

From man ftp http://linux.die.net/man/1/ftp

-p passive mode
-P port

or if with a version of ftp that does not support -P (Debian 9/Ubuntu 16.04):

ftp -p localhost 2121

I will also leave a link to “SSH tunnels local and remote port forwarding explained”


Lastly, I would advise on not using root in the remote system for ssh connections. root is a very powerful account, and should only be reserved for system administration.

Furthermore, in many modern Linuxes ssh remote login as root comes disabled by default.

Why is root login via SSH so bad that everyone advises to disable it?

Answered By: Rui F Ribeiro
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.