Useful things you can make SSH do
derwiki.tumblr.com
derwiki.tumblr.com
Host *.internal.workdomain.com
ProxyCommand ssh gateway.workdomain.com nc %h 22
ForwardAgent yes
User <username>
Then you can type ssh bender.internal.workdomain.com
and ssh will automatically connect through the gateway to the (normally inaccessible) internal node. ForwardAgent will pass the credentials through. (If you copy this blindly, note that this requires netcat). This configuration lets you pretend (to tools like scp, rsync-over-ssh, etc) that you have direct access to the machine in question, even when it goes through a gateway machine: scp config bender.internal.workdomain.com:
scp bender.internal.workdomain.com:logfile . Host foo
ProxyCommand corkscrew proxy.domain 3128 %h %p ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p- Get a cheap development box (Linode, Slicehost, etc.)
- Set Firefox to use Socks Host 127.0.0.1:8080
- Open up your terminal and enter this: ssh -C2qTnN -D 8080 your-user@example.com
Et voilà, you're tunneling all your browser traffic through the development box.
I was trying to make a shell script just the other day that would set up a SSH SOCKS proxy to a remote box and launch a browser using it, but couldn't do it from the command line in either Firefox or Chrome (didn't try a custom profile). Furthermore, I couldn't get it working in Chrome at all (shame; Firefox is more sluggish, and Opera won't even start on my box).
I'm unsure how to make it do remote DNS look-ups though.
Opera cannot do SOCKS.
function remotebrowse() {
export SOCKS_SERVER=localhost:5432
ssh -fNTD 5432 remote
google-chrome --user-data-dir=/tmp/chrome $1 &
}
I get some error messages, but it seems to work.This is useful when the local network is untrusted, or to bypass things like url blocklists or IP filtering.
The arguments are as follows:
ssh -C2qTnN -D 8080 your-user@example.com
C2: request compression, at level 2 (1 is least)
q: quite mode
T: Disable pseudo-tty allocation. I don't know why you would want this. I suspect since you are only using it for a proxy you don't really need a tty, but seems a little unnecessary to me.
n: redirect stdin from /dev/null. Again, not sure why this is needed, but I suspect it is related to the "T" option.
N: Do not execute a remote command. You are only using port forwarding so no commands are needed.
-D 8080: the local port to forward
your-user@example.com: Username/host of remote machine.
This is a pretty optimized example. The simplest working version is just ssh -D 8080 your-user@example.com. Personally, I'd use the -C2 argument as well, but leave the rest out.
Similarly, -n is described as necessary for backgrounding the process, if you want to. I can't find a reason to use -T, unless you intend to send binary data over the pipe.
A typical use for this is when you are connected to a foreign network like a hotel. If you don't route your http traffic over ssh, there is a risk of having your traffic sniffed and/or recorded.
- watch Hulu, when you're not in the US
- use Spotify when you are in the US (and you use a UK box for example)
- bypass your university firewall
- in general secure your connection in case you are using an open network
Host backup-server
HostName backup.example.com
User backup
IdentityFile ~/.ssh/backup_dsa
Then just have a shell script run $ ssh backup-server
It ended up working really well.Also, control sockets.
1. Comparing local and remote files
$ ssh user@123.4.5.6 "cat /tmp/remotefile" | diff - /tmp/localfile
2. Outputting your microphone to a remote computer's speaker
dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp
diff <(ssh user@host cat remote-filename) local-filename
is a bit more intuitive too. You can put anything that writes to stdout in the <(), too. (Useful for decrypting or decompressing on the fly.) $ ssh user@host "tar cvzf - /path" | tar xvzf - /pathAlso - another trick is to give it -c blowfish to use a lighter/faster cipher for the transfer to save on CPU time.
$ scp -r user@host:/path /path
This is especially bad if you have a directory structure that references a higher-level directory.
We found a lot of fun sounds to blast at him while he slept. :)
>ssh -X user@remoteserver.com will connect you. >gedit file.txt
will launch a remote instance (viewable locally) of gedit with the remote file.txt loaded and ready for editing. Especially good for those who don't like command line editors (note: gedit must be installed on the remote machine for the example to work.)
I usually bookmarks the Tramp sessions of the frequently visited servers to avoid retyping the host url and logon setting.
ssh -T host
(of course syslog still sees you).
if available, ssh-copy-id(1) is an easier way of setting up passwordless ssh(1).
note also that openssh supports on-demand proxying via SOCKS4/5: check out ssh -D. this makes it easy to pipe all web traffic (for example) over ssh.
ssh -T foo bash -i Got a computer behind a firewall whose configuration
you don’t have access to? It’s pretty easy to get the
computer behind the firewall to poke out to another
server.
(step 1, from the computer you wish to access)
derwiki@firewalledcomputer:~$ ssh -R localhost:2002:localhost:22 mypublicserver.com
(step 2, from any computer than can access
mypublicserver.com)
derwiki@mylaptopontheinternet:~$ ssh mypublicserver.com -p 2002
(authenticate)
derwiki@firewalledcomputer:~$
If you want to keep it running always, you may want to consider "autossh" (restarts ssh connections if they ever exit/disconnect)My setup is to keep ssh-agent running with a 2-hour lifespan, and connect to that automatically when I log in. Basically this:
$ ssh-agent -t 7200 > ~/.ssh-agent
$ echo "source ~/.ssh-agent" >> ~/.bash_profile
$ [... log in ...]
$ ssh-add
I am not annoyed by re-entering my passphrase every two hours.But by the same token though, why document any code? It executes the same no matter what comments are around it, and all the underlying operations are well documented.
http://proxytunnel.sourceforge.net/usage.php
Also, as others have mentioned, -D is pretty useful (SOCKS proxy).