Recent Changes - Search:

Basics

Languages

Tools

OS

Resources

PmWiki

pmwiki.org

edit SideBar

Forwarding

Forwarding is the act of setting up a connection between your local computer and a remote computer by going through a server. This is often done to circumvent network limitations (ex.: Firewalls not allowing direct remote connections, but enabling connections to a server, which means you can reach the remote computer through the server).

Local forwarding

Local forwarding is setting up a way for a remote server to forward a request from the local computer onto the remote network. Setting up the forwarding is done through:

ssh -L LocalPort:remoteIPAddress:RemotePort username@server

where username@server are the login information for the server which will do the forwarding, LocalPort is the port through which the connection will be used locally, remoteIPAddress is the IP address of the remote computer to be reached through the forwarding and RemotePort is the port on the remote machine which will be accessed (ex.: 22 for ssh/scp permissions).

To then access the remote computer, one can use SSH:

ssh remoteUsername@localhost -p LocalPort

to ssh to the remote computer. This is equivalent to using ssh to access the server, then using ssh again to access the remote computer from the server. The main interest is using SCP to transfer files directly from the remote computer to the local computer, without having to go through the server except for the forwarding, using:

scp -P LocalPort remoteUsername@localhost:path/to/remote/file path/where/to/put/file

To copy all the files in a folder:

scp -r -P LocalPort remoteUsername@localhost:path/to/remote/folder path/where/to/put/folder

Accessing remote computers with one command

For remote computers that you want to access often (ex.: a desktop at work), the information can be stored in your .ssh/config file to make things easier:

Host server
    User serverUsername
    Hostname serverAddress

Host remoteComputer
    User computerUsername
    Hostname remoteComputerAddress
#    Port 2222
    ProxyCommand ssh -q -W %h:%p server

with this done, you can now use ssh remoteComputer and, after entering two passwords (one for the server, one for the computer) you will be logged in. This also works with scp and rsync! Although this accomplishes essentially the same thing as a succession of ssh server and ssh remoteComputer (or a much more cumbersome succession of scp/rsync), it does things slightly differently, using the server to establish a connection without creating a session. You can make the connection even smoother by using SSH-Keys to only have to type your passphrases once, then any subsequent ssh/scp/rsync command will run immediately. Note: You define two keys on your local computer: one for the server, one for the remote computer. It is unnecessary to define a key on the server for the remote computer (for this application).

Edit - History - Print - Recent Changes - Search
Page last modified on June 12, 2019, at 03:05 PM