pf » Setting up public key authentication over SSH
Setting up public key authentication over SSH


Every time I want to setup public key authentication over SSH, I have to look it up, and I've never found a simple guide, so here's mine.
Generate key on local machine
ssh-keygen -t rsa
It will ask you for a password but you can leave it blank.
Note you could also pick -t dsa if you prefer.
Ensure that the remote server has a .ssh directory
Make sure the server your connecting to has a .ssh directory in your home directory. If it doesn't exist you can run the ssh-keygen command above, and it will create one with the correct permissions.
Copy your local public key to the remote server
If your remote server doesn't have a file called ~/.ssh/authorized_keys2 then we can create it. If that file already exists, you need to append to it instead of overwriting it, which the command below would do:
scp ~/.ssh/id_rsa.pub remote.server.com:.ssh/authorized_keys2
Now ssh to the remote server
Now you can ssh to the remote server without entering your password.
Security
Now keep in mind that all someone needs to login to the remote server, is the file on your local machine ~/.ssh/id_rsa, so make sure it is secure.
Related Entries
- Howto Backup your Mac incrementally over SSH - March 10, 2006
- Top 20 Internet Security Vulnerabilities of 2005 - November 23, 2005
Thanks a million Nav
any help would be appreciated.
thanks, Dan
authorization contains line like Key _private_key_file_name_here_
HTH, Alex
cat ~/.ssh/id_dsa.pub | ssh someguy@somesite.com "cat - >> ~/.ssh/authorized_keys"
server$ chmod 700 ~/.ssh server$ chmod 600 ~/.ssh/authorized_keys
That should sort out most problems. More info here: http://sial.org/howto/openssh/publickey-auth/
server$ chmod 700 ~/.ssh server$ chmod 600 ~/.ssh/authorized_keys
So all i have to do is like input machine details and have it send the ssh key over to the remote machine automatically. i can code it in just having a problem, when i run scp filename user@ip:.ssh . How do i send the password via the php script when it asks. I tried doing a system command with the password but it doesn't work. Nor does it produce any kinda output.
I am using the System() Php Function.
- CFSCRIPT Cheatsheet
- 3 New Image Effects for ColdFusion 8
- Googlebot to Submit Web Forms
- ColdFusion 8 Update 1 Fixes some Image Processing Quirks
- 10 Most Useful Image Functions in ColdFusion 8
- Speaking at NYC CFUG This Week
- Adobe AIR Tutorial for HTML / JavaScript Developers
- INFORMATION_SCHEMA Support in MySQL, PostgreSQL
RSS
add to del.icio.us
Pete Freitag is a software engineer, and web developer located in








