December 19, 2008

Set up ssh key pairs

0  comments

With ssh key pairs you can easier login to your servers. To generate an ssh key pair you´ll need to run the following line in your terminal:
ssh-keygen -t dsa
It will ask you for location and pass phrase. You should accept the default location (~/.ssh/id_dsa.pub). For the pass phrase I usually just press return. Then the private key will have a blank pass phrase and you can login to your servers without a password. Comfort vs. security. Your choice. After this you need to upload the public key to the server.
scp ~/.ssh/id_dsa.pub you@yourserver.com:
Finally login to the server and append the public key to authorized keys:
ssh you@yourserver.com
mkdir .ssh          # if it's not already there
cat id_dsa.pub >> .ssh/authorized_keys
rm id_dsa.pub       # cleanup
Make sure that the .ssh folder and the authorized_keys have the right permissions:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
After this, you should be able to login to the server and use scp without having to enter a password. If you login or copy files to your servers a lot, you can setup an alias in ~/.ssh/config (on your local machine):
Host ys
HostName yourserver.com
User you

Tags

Linux, scp, ssh, sshkeypairs


You may also like

Blog url changed to https

I just changed the url of this blog to https://jensjaeger.com. TLS encryption is now the default for all request to this page. It might be possible that some image links on some articles are hard coded http. If you find such an error it would be nice if you leave me comment so i can

Read More

Format date and time in java with prettytime

Prettytime is a nice java library to format a java Date()s in a nice humanized ago format, like: moments ago 2 minutes ago 13 hours ago 7 months ago 2 years ago Prettytime is localized in over 30 languages. It’s super simple to use Add the dependency to your maven pom: org.ocpsoft.prettytime prettytime 3.2.7.Final or

Read More