Contents

Generate login key for passwordless entry

Have have dealt with this before (as a side note), but wanted to re-iterate this process. Because I use ssh so much I get tired of having to enter passwords constantly. Now I will preface this by saying only do this on a network you trust. Yes you will be logging into ssh with a certificate, and that certificate will be on your machine, but you don’t want to employ this method on a network that can not be trusted. With that in mind, here are the steps for setting this up.

On the local machine issue the command:

ssh-keygen -t dsa

This command will generate a public key that will be then copied to your server. During this creation process you will be asked for a password – just press enter to use a blank password for this. You will have to verify the password, so hit enter again. )

With the key created you have to copy it to the server you want to ssh into. To do this enter the command:

ssh-copy-id -i .ssh/id_dsa.pub username@destination

Where username is the username you will be logging into on the remote server and destination is the IP address of the remote server.

Now when you go to secure shell into that remote machine you will not have to enter a password.

Using tar and ssh to efficiently copy files preserving permissions

Have you had situations where disk-space is sparse, so making full tars (although compressed) is impossible? Here is an ssh trick that could help you copy over files without using too much diskspace.

This trick will tar a directory from a computer, but the file that it would normally create, is standard out, so it is redirected back to the script on the computer you are working on. The computer you are working on extracts the information directly, so there is no location where (redundant) files are stored.

ssh user@machine-where-precious-data-is "tar czpf - /some/important/data" | tar xzpf - -C /new/root/directory

You are now directly copying data from the “machine-where-precious-data-is” to the machine you are working on, using the benefits of tar (preserving permissions, links, etc) but not being hindered by the difficulties of tar. (making these possibly large files and so on.) I used this trick to copy users directories from one machine to the other. An alternative command, reverse and not crossing filesystem boundries:

tar czpf - /some/important/data | ssh user@destination-machine "tar xzpf - -C /some/directory/"

References

  1. Password-less login
  2. Efficient ssh copy