Bored? Check out the Recent Activity on Siafoo Join Siafoo Now or Learn More

Unix/Linux Tips and Tricks Atom Feed 0

Make working in the shell suck less.


Config File

To save typing, edit your ~/.ssh/config file to create aliases and default logins for each host you commonly log in to. Just include stanzas like this:

Host some-alias
HostName some-host-name-that-gets-really-long.example.com
User yourname

Now instead of typing ssh yourname@some-host-name-that-gets-really-long.example.com you can just type ssh some-alias to do the same thing.

If you get an error such as Bad owner or permissions on /home/yourname/.ssh/config then you will just need to set the correct permissions for the config file

chmod 600 ~/.ssh/config

Authorized Keys

Most servers support asymmetrical (public/private) key authentication, meaning you don't have to type in your password every time. All you need to do is append your public key to the end of the ~/.ssh/authorized_keys on the server.

What? Don't have a key? Thats okay, create one with ssh-keygen. This will create a public/private key pair, with each one in a separate file. Your public key has the .pub extension; by default it is called ~/.ssh/id_rsa.pub.

To add it to the server, you can use the program ssh-copy-id (If in OS X, you won't have this, but can install with brew install ssh-copy-id if you have brew). Just run ssh-copy-id user@machine. You'll have to include a -i identity_file if your public key isn't in the default place. Finally if you're already using public key auth for some reason (like Amazon AWS), and want to copy your key over, you won't be able to use this. Instead do something like:

cat ~/.ssh/id_rsa.pub | ssh -i old_key user@machine 'cat - >> ~/.ssh/authorized_keys'

This pipes your key into the command that ssh runs on the server, which in turn appends that into authorized_keys on the server.


Did you know you could have ssh run a command on the server and exit? What's the big deal? You can save tons of typing and scp-ing if you're clever. For example, you can clone a postgresql database onto your local machine with one command:

ssh user@machine pg_dump remote_source_db | psql local_dest_db

Did OS X vomit a bunch of .DS_Store files all over your directory tree? Just use the Dos Equis of commands, find, like this:

find . -name '.DS_Store' -exec rm -f {} \;


over 9 years ago (01 Mar 2011 at 11:16 AM) by Stou S.
Yay! I've been wanting to do this for a week now but I was too lazy to Google it.