70

I am looking to set a proxy for terminal. What I need is I want to send all terminal communications to the internet through a proxy, say tor.

I tried to set a system wide proxy set up. But Terminal doesn't obey the system wide proxy configuration.

Is there any other way to do this?

muru
  • 193,181
  • 53
  • 473
  • 722
Anonymous Platypus
  • 3,730
  • 10
  • 33
  • 51
  • You mean ssh or telnet or ... ? Please explain us "terminal communications". You can telnet to some host via proxy or ftp them, but communication from minicom you can not send via net ... except like log file .... – 2707974 Feb 10 '15 at 13:49
  • 2
    Is it possible to set a proxy for all network related activities done over the terminal? Instead of setting proxy for wget,curl and others separately. I am looking for such a solution. – Anonymous Platypus Feb 11 '15 at 05:18
  • Yes, but wget usually work on port 80 or 443, ssh on port 22, telnet on 23, ftp on 20 and 21 ... You can use [simpleproxy](http://manpages.ubuntu.com/manpages/gutsy/man1/simpleproxy.1.html) or [tinyproxy](http://manpages.ubuntu.com/manpages/intrepid/man8/tinyproxy.8.html) – 2707974 Feb 11 '15 at 08:15
  • How to set this proxy for terminal? Do I explicitly set it for different apps running on terminal or can I set it in terminal such a way that all the commands I run in terminal go through this proxy? – Anonymous Platypus Feb 11 '15 at 08:29
  • 1
    ubuntu terminal needs http proxy, when you use SOCKS5 proxy, like shadowsocks, you can use `proxychains` to bridge SOCKS5 to http proxy. Check this https://github.com/shadowsocks/shadowsocks/wiki/Using-Shadowsocks-with-Command-Line-Tools – hakunami Nov 02 '17 at 14:43
  • you can `export LD_PRELOAD=/usr/lib/*yourarch*/torsocks/libtorsocks.so` – Yvain Apr 14 '19 at 07:41

6 Answers6

75

export the below variables in terminal

export http_proxy='http://proxyServerSddress:proxyPort'    
export https_proxy='https://proxyServerSddress:proxyPort'

and use the following commands to disable proxy

unset http_proxy
unset https_proxy
αғsнιη
  • 35,092
  • 41
  • 129
  • 192
PKumar
  • 2,852
  • 3
  • 11
  • 12
35

Terminal is not net application. Maybe is better to say, in your case, terminal is container for net application like ssh, telnet, lftp, wget, lynx ...

Edit your:

sudo -H gedit /etc/profile.d/proxy.sh

Enter the details in this format.

export http_proxy=http://username:password@proxyhost:port/ 
export ftp_proxy=http://username:password@proxyhost:port/
export telnet_proxy=http://username:password@proxyhost:port/

This is for when using wget, ftp, lftp, telnet in terminal

ssh has no native SOCKS client support, you need to use a ProxyCommand for that, for instance with socat:

ssh -o ProxyCommand='socat - SOCKS4A:myproxy:%h:%p,socksuser=nobody' user@host

Or use things like tsocks to transparently use SOCKS for TCP traffic.

For SOCKS5 with socat 2:

ssh -o ProxyCommand='socat - "SOCKS5:%h:%p|tcp:myproxy:1080"' user@host

For HTTP Proxy CONNECT method with socat 2:

ssh -o ProxyCommand='socat - "PROXY:%h:%p|tcp:myproxy:80"' user@host
muru
  • 193,181
  • 53
  • 473
  • 722
2707974
  • 10,363
  • 6
  • 31
  • 44
2

In my case I was either missing enclosing inverted comma on both sides. putting "http//.." was wrong and not putting anything such as http//... was wrong too. What worked was ..when I used single inverted commas on both sides.

export http_proxy='http://username:password@proxyhost:port/' export https_proxy='https://username:password@proxyhost:port/' export ftp_proxy='http://username:password@proxyhost:port/'

Remember these three are 3 commands to be run separately three times.

2

using torsocks this can be accomplished like so:

ultralazer@askubuntu:~$ torsocks --shell
New torified shell coming right up...

ultralazer@askubuntu:~$ curl icanhazip.com
185.220.100.242 (tor ip)

man page:

ultralazer@askubuntu:~$ torsocks --help
ultralazer@askubuntu:~$ man torsocks
ultralazer
  • 21
  • 1
1

I set export variables

export http_proxy=http://username:password@proxyhost:port/ 
export https_proxy=https://username:password@proxyhost:port/
export ftp_proxy=http://username:password@proxyhost:port/

in ~/.bashrc and /etc/enviroment

Francuz
  • 111
  • 3
1

From my research this was the only thing that worked for me:

Install ProxyChains:

sudo apt-get install proxychains

Edit the conf file to use your proxy:

sudo vi /etc/proxychains.conf

Check the last line and edit it. Then just run:

proxychains ssh/curl/wget 

or whatever command you want to go through the proxy.

This is someone else answer