I have a problem in accessing Internet through an ssh-accessible server


EDIT: FYI, my OS is Ubuntu 16.04, and IIRC, same as the server.

Ok, here's the deal.

  • My company provide me a PC with network connection (through a proxy), but got limited to some resources on the net (I can neither add external PPA or apt-get update after manually adding them, nor can't access to some download section of some applications, but still can install package by using apt-get install or pip).
  • Besides, my (above) PC have access to some of my company's servers via ssh connection. One of them (deliberately) has unrestricted Internet access (sounds weird, but that the way it is). I asked my boss if I can somehow can make my computer connect to the Internet without restriction through that server, and he told me that's possible but he doesn't know how to. And FYI, though he doesn't encourage me to do so, I'm not forbidden.

My question

Is there any way I can do what I've just describe? From my PC, access (unrestricted) to Internet via a remote server (with unrestricted Internet access)

What I've tried so far

Not much, actually, because I don't know how to search (hard to think of a keyword) for the problem. Most of the time I tried to config the proxy, so I can (partially) solve the problem (for PPA, I tried adding to source.list and add the sign, add proxy entries to /etc/apt/apt.conf, ...). Still no candy for the baby. If anyone need to see the error, tell me, but I want to solve the problem completely :(

I'm grateful to any suggestion. Thanks in advance!

  • Is you PC with unrestricted acces to Internet a linux box ? If yes, take a look at askubuntu.com/questions/609922/…
    – olikaf
    Jul 9, 2018 at 10:13
  • In some parts of the world, violating your company's policy on the care and use of their property (regardless of your supervisor's apparent lack of interest) might get you fired and/or sued. If they truly didn't care, then why did they go through so much trouble to require use of their proxy under all possible conditions?
    – user535733
    Jul 9, 2018 at 12:04
  • Do you have full admin permissions on this machine? If so, please edit the question to clearly explain exactly what happens when you disable the proxy and try to use normal non-proxied networking. "It doesn't work" is too vague to help you -- we need to see the complete error messages that explain why it doesn't work.
    – user535733
    Jul 9, 2018 at 12:09
  • @olikaf it is. I will try your suggestion
    – enamoria
    Jul 10, 2018 at 1:18
  • @user535733 I have full permission on both device (mine and the server). I asked my boss about my situation and I got his permission to do it (though he suggest me to try figure a workaround first)
    – enamoria
    Jul 10, 2018 at 1:18

4 Answers 4


Try SSH tunneling/port forwarding. There is a lot of information in Internet. Read this: SSH/OpenSSH/PortForwarding and SSH tunneling with ubuntu.

I like to use SSH socks-proxy. Install plink:

sudo apt install plink

Run command in your local computer (SSH client) with restricted access to Internet:

plink -ssh -C -N -l user -D

where - IP-address of your remote SSH-server with unrestricted access and user - your SSH-server username.

Thats all. Now you have SOCKS proxy - all of the traffic through the proxy will be encrypted and routed through your remote SSH-server. Settings for the proxy are: host, port 8081.

Add this settings as Ubuntu system-wide proxy settings and instruct browsers, bash etc. to use system proxy. It's possible to add system proxy with Ubuntu System Settings GUI (mine has Ukrainian locale): enter image description here

If you want to use the proxy for apt, read Configure proxy for APT?, only take into account you have socks-proxy, thus the proxy URLs should be socks4:// or socks5:// instead of, for example:

export http_proxy="socks4://"
  • 2
    What does the plink do? I just use ssh.
    – user68186
    Jul 9, 2018 at 10:35

Two Steps to Use Socks Proxy

Socks proxy allows an easy way to access the Internet using a proxy computer. In this case the server that has unrestricted access to the Internet.

Step 1: Setup socks proxy for the desktop

This can be done at the browser or the system level. We will do it at the system level so that any program that wants to access the Internet will use the socks proxy. We will do it using the command line.

Open a terminal at your desktop Ubuntu using Ctrl+Alt+T and enter the following lines:

gsettings set org.gnome.system.proxy.socks host 'localhost'
gsettings set org.gnome.system.proxy.socks port 1080
gsettings set org.gnome.system.proxy mode 'manual'

This will route all the Internet traffic via the localhost:1080.

Step 2: ssh with a few options

Let us say the server has the IP address aaa.bbb.ccc.ddd and you have an user account in this server called user007.

In the terminal enter:

ssh user007@aaa.bbb.ccc.ddd 

If this works, you are all set. type exit to get back from the server to the desktop. Now lets do it again with some options:

ssh -CD 1080 user007@aaa.bbb.ccc.ddd 
  • The C compresses whatever passes between the desktop and the server.
  • The D 1080 binds the local port 1080 to the server.

To revert back to normal

First, exit out of the ssh session. If you add the -N option in the ssh you will have to use Ctrl+C.

Second, change proxy to none:

gsettings set org.gnome.system.proxy mode 'none'

If you want to be fancy, you can combine these steps into a bash script, but this will get the job done.

gsettings set org.gnome.system.proxy.socks host 'localhost'
gsettings set org.gnome.system.proxy.socks port 1080
gsettings set org.gnome.system.proxy mode 'manual'
ssh -CD 1080 user007@aaa.bbb.ccc.ddd
gsettings set org.gnome.system.proxy mode 'none'
echo "Finished with the Internet, now back to work..."

This script will set the socks proxy, then start the ssh. When you exit the ssh, it will turn the proxy off.

Hope this helps


The other answers work for things that have support for SOCKS in their configuration. When the tool you want to use doesn't have support, you can use socksify from the dante-client package.

ssh -fND 1080 $server
SOCKS_SERVER= socksify git fetch

Ok. I've forgot about this question. Sorry, I should update the situation earlier.
I've tried some of the above suggestion. One of them works, the others didn't (some error that I can't recall, maybe due to my configuration). The solution is quite complicated (I have to google a bit to get it real works).

An eas(ier) solution

Then one of my colleagues suggest me to use sshuttle and within a single command, I got what I need. All I have to do is open a new terminal, type in sshuttle -r username@serverIP and enjoy the whole world of Internet. Sometimes it will return error and strangely just retrying makes it work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.