This is useful for a machine that needs to clone some repository from github, but does not having internet connection.
$ ssh -qN -D 1234 proxy-server
$ git -c http-proxy=socks5h://localhost:1234 clone https://github.com/30-seconds/30-seconds-of-code
Linux is for everybody. Lets enjoy it.
This is useful for a machine that needs to clone some repository from github, but does not having internet connection.
$ ssh -qN -D 1234 proxy-server
$ git -c http-proxy=socks5h://localhost:1234 clone https://github.com/30-seconds/30-seconds-of-code
This is useful when you have a server that is not allowed to go to the internet, but have an ssh connection to another server that is able to go to the internet (we can call it jumphost).
1. Setup a socks proxy on port 8888 (any port will do, 8888 is just my preference) via the jumphost
# ssh -D 8888 -fN user@jumphost
2. Append below line into yum.conf
# cat >> /etc/yum.conf <<EOF
proxy=socks5h://localhost:8888
EOF
3. Yum away (or run the yum command). All yum command will now tunneled through jumphost
# yum update
4. Once done, kill the socks proxy connection
# kill -9 $(ps -ef | grep fN | grep -v grep | awk '{print $2}')
5. And remove the proxy setting in /etc/yum.conf
# sed -i '$d' /etc/yum.conf
This is useful when we have a machine (m1) that does not have an internet connection to do apt update/upgrade, but we have another machine (m2) that is able to access internet, and accessible via ssh from the m1.
Create a dynamic tunnel (socks5 proxy) from m1 to m2, using port 8888
$ ssh myuser@m2 -fN -D 8888
Set apt to use the socks proxy created above
$ echo "Acquire::http::proxy "socks5h://localhost:8888";" | sudo tee -a /etc/apt/apt.conf.d/12proxy
Run apt command as usual in m1, and your apt command will be tunneled via the socks5h proxy
$ sudo apt update
...
0% [Connecting to SOCKS5h proxy (socks5h://localhost:8888)] [Connecting to SOCKS5h proxy (socks5h://localhost:8888)]
Recently, I encountered an error while trying to update ubuntu server 16.04. The error is as below:
This is useful when you have a CentOS/Redhat server that needs to be updated, but does not have internet connection to get app from the repo. The only requirement is that the server need to be able to ssh into another server that have internet connection. Let's begin.
Download source for proxychain. You can use the server that have internet connection to do this
# wget -c https://github.com/rofl0r/proxychains-ng/archive/master.zip
Transfer the downloaded file into the server without internet, and unzip the file into /usr/local/src
# unzip master.zip -d /usr/local/src
Change directory to /usr/local/src/proxychains-ng-master
# cd /usr/local/src/proxychains-ng-master
Compile, configure and make
# ./configure && make && make install && make install-config
Setup a dynamic socks proxy on port 8888 by ssh'ing into the server that has internet connection:
# ssh foo@server.with.internet -D 8888
Set proxychains to use the dynamic tunnel, by changing the last line of /usr/local/etc/proxychains.conf to "socks4 127.0.0.1 8888"
# tail -1 /usr/local/etc/proxychains.conf
socks4 127.0.0.1 8888
This issue happened when one day, my lovely company decided that they want to implement a proxy server, and without me realizing, not just browser will be affected, apt-get also will be affected.
How do you know that you apt-get command encounter proxy issue, when ypu received "401 authenticationrequired" error after running your apt-get command, like below:
$ sudo apt-get update ... W: Failed to fetch http://my.archive.ubuntu.com/ubuntu/dists/raring-updates/universe/binary-i386/Packages 401 authenticationrequired ...
$ sudo export http_proxy='http://myusername:mypassword@myproxyaddress:myproxyport'
$ sudo bash -c 'http_proxy="http://myusername:mypassword@myproxyaddress:myproxyport/" apt-get update'
$ echo "http_proxy='http://myusername:mypassword@myproxyaddress:myproxyport'" >> .bashrc
$ source .bashrc
$ sudo echo -e 'Acquire::http::proxy "http://myusername:mypassword@myproxyaddress:myproxyport/";\nAcquire::https::proxy "https://myusername:mypassword@myproxyaddress:myproxyport/";\nAcquire::ftp::proxy "ftp://myusername:mypassword@myproxyaddress:myproxyport/";\nAcquire::socks::proxy "socks://myusername:mypassword@myproxyaddress:myproxyport/";' >> /etc/apt/apt.conf
This technique is very useful if you have a firewall between you and your destination, and somehow the only way you could get in to the destination is by ssh'ing into a jumpbox and ssh again to the destination. In this scenario example, I'll call the machine we initiate this technique as A.local, the jumpbox as B.local and the destination server as C.local, and we will use a user called aladdin.
A.local -> B.local (jumpbox) -> C.local
To do this, please follow below steps:
Host B.local
DynamicForward localhost:1080
Host C.local
ProxyCommand /usr/bin/nc -x localhost:1080 %h %p
[A.local]$ ssh -D 1080 aladdin@B.local
[A.local]$ ssh aladdin@C.local
[A.local]$ ssh -o "ProxyCommand /usr/bin/nc -x localhost:1080 %h %p" aladdin@C.local
[A.local]$ alias alias proxyssh='ssh -o "ProxyCommand /usr/bin/nc -x localhost:1080 %h %p"'