//Tips tagged ssh
Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
tab completion is something we use all day long. put this into your .bash_profile. You can use tabs to auto complete the hostname for ssh calls.

complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq | grep -v "\["`;)" ssh

View Comments »

You can use the following to output your microphone to a remote computer's speaker:

dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp

This will output the sound from your microphone port to the ssh target computer's speaker port. The sound quality is very bad, so you will hear a lot of hissing.

View Comments »

Many people use netcat on both the remote and local machine in order to transfer stdin and stdout to and from machines over the network, but many don't realize you can do the exact same thing using one line with SSH:

ssh remote_machine 'cat - > file' < file

Of course that is useless since if you have ssh access, you can use scp or sftp, but what is more useful is inserting ssh anywhere in a pipeline to run a command on the contents on a remote machine. For example:

wget -O - http://ftp.mozilla.org/.../thunderbird-3.0b2-i686.tar.bz2 | ssh remote_machine 'tar xjvf -'

That will download the latest nightly build of Firefox 3.0 and extract it on remote_machine.

Of course, it works both ways:

ssh remote_machine 'wget -O - http://ftp.mozilla.org/.../thunderbird-3.0b2-i686.tar.bz2' | tar xjvf

That downloads Firefox on the remote machine and extracts it on the local machine.

That example is still kinda useless, but combine it with tee and command substitution, and you have a nice way to distribute the same tarball to multiple hosts:

wget -O - http://ftp.mozilla.org/.../thunderbird-3.0b2-i686.tar.bz2 \
| tee >(ssh host1 'tar xjvf -') | tee >(ssh host2 'tar xjvf -') | ssh host3 'tar xjvf -'

You can pretty much use ssh anywhere you want to send stdin to or receive stdout from remote machine commands. Using netcat sends everything in the clear, and if you have the access to run netcat, you probably have ssh access.

View Comments »

nice ssh username@remoteservername "tar cjf - -C /from/basedir/ dirtocopy" | tar xjvf - -C /to/dir/ ; sleep 120 ; shutdown -P now

Copy the remote directory dirtocopy from the remote server to dir of local machine. Transfer the contents using bzip2 compression. When it's done (even if it fails) wait 120 seconds and power off the machine.

View Comments »

Suppose we have to find the differences between local file "/tmp/localfile" and remote file "/tmp/remotefile" located on remote host

This is how can do it:
$ ssh user@ "cat /tmp/remotefile" | diff - /tmp/localfile

And using vimdiff:
$ vimdiff scp://user@ /tmp/localfile

(of course we would need ssh to work using public key authentication so that we can do remote commands execution without being prompted for passwords).

View Comments »

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit