- [Instructor] In the previous video
we looked at passwordless auto-login with SSH.
This video talks about port forwarding
and mounting a remote drive.
Here we will look at the commands for port forwarding
on a local system and then on a remote one.
After that we'll see non-interactive port forward.
Then we'll talk about reverse port forward.
Finally we'll see how to mount a remote drive
at a local mount point.
Port forwarding is a technique by which you can enable
other computers to connect to a particular service
on a remote server using your machine.
To understand this with an example,
let's say your machine is assigned the IP 192.168.1.2
on a network, and it has an internet connection as well.
Now if you forward your machine's port 8000
to port 80 of www.kernel.org,
it will be possible for some other computer
to access the Linux kernel website
by going to http://192.168.1.2:8000 using a browser.
Let's see how to do this.
There are two ways in which you can forward your port.
You can either forward a port
in your local machine to another machine,
or you can forward a port on a remote machine
to another machine.
In these methods you will eventually get a shell prompt,
once the forwarding is complete.
Keep this shell open to use the port forward
and exit it whenever you want to stop the port forwarding.
One, use this command to forward a port 8000
on your local machine to port 80 of www.kernel.org.
Here replace the user with username on your local machine.
Two, you'll need to use this command to forward a port 8000
on the remote machine to port 80 of www.kernel.org.
Here replace remote machine with the host's name
or IP address of the remote machine,
and user with the username that you have SSH access to.
Port forwarding can be made more useful
by using non-interactive or reverse port forwarding.
Let's see these.
The first one is non-interactive port forward.
If you want to just set the port forwarding
instead of having a shell to be kept open
for the port forwarding to be effective,
use this form of SSH.
The -f instructs SSH to fork to background
just before executing the command,
and -l for the login name for the remote machine.
Minus capital N tells SSH that there is no command to run.
We only want to forward ports.
Cool.
Now let's see reverse port forwarding.
It's one of the most powerful features of SSH.
This is most useful in situations where you have a machine
which isn't publicly accessible from the internet,
but you want others to be able to access
a service on this machine.
In this case if you have SSH access on a remote machine
which is publicly accessible on the internet,
you can set up a reverse port forward on that remote machine
to the local machine which is running the service.
Reverse port forwarding is very similar to port forwarding.
This will forward port 8000 on the remote machine
to port 80 on the local machine.
As always don't forget to replace remote machine
with the host name or the IP address of the remote machine.
Using this method if you browse to http://localhost
on the remote machine,
you will actually be connected to a web server
running on port 8000 of the local machine.
Awesome.
Now let's move on to mounting a remote drive.
Having a local mount point to access the remote host
filesystem is really helpful while carrying out
both read and write data transfer operations.
SSH is the common transfer protocol available in the network
and hence we can make use of it here with SSHFS.
This enables you to mount a remote filesystem
to a local mount point.
Let's see how to do it.
SSHFS doesn't come by default with GNU Linux distributions.
Install SSHFS by using a package manager.
SSHFS is an extension to the FUSE filesystem package
that allows supported OS to mount a wide variety of data
as if it were a local filesystem.
For more information on FUSE visit its website
at github.com/libfuse/libfuse.
How to do it.
In order to mount a filesystem location at a remote host
to a local mount point, use...
Okay, so I haven't installed SSHFS yet.
Let's do that now.
Issue the password when prompted
and data at home/path on the remote host
can be accessed via our local mount point /mnt/mountpoint.
In order to unmount after completing the work,
use umount like so.
In this video we've learned all about port forwarding
and mounting a remote drive.
In the next video let's talk about network traffic
and port analysis.