View Full Version : [ubuntu] how to ssh/scp without having to enter password each time?
sa125
May 6th, 2009, 02:08 AM
Hi -
I find that I need to ssh/scp to remote machine quite a bit, and it's quite annoying to enter a password every time I do so (hourly basis). I know there's a way to authenticate a connection with a key file (ssh-keygen -t rsa), but I'm not sure what needs to be saved where on the remote machine. I'd appreciate a very brief walk through to help clarify this, like:
1. create keyfile with $ ssh-keygen -t <rsa|dsa>
2. copy the pub file to ...
Thanks!
Kobalt
May 6th, 2009, 05:55 AM
Hello,
See this for some guidance : https://help.ubuntu.com/community/AdvancedOpenSSH#RSA%20Key-Based%20SSH%20Logins
bodhi.zazen
May 6th, 2009, 12:27 PM
Hi -
I find that I need to ssh/scp to remote machine quite a bit, and it's quite annoying to enter a password every time I do so (hourly basis). I know there's a way to authenticate a connection with a key file (ssh-keygen -t rsa), but I'm not sure what needs to be saved where on the remote machine. I'd appreciate a very brief walk through to help clarify this, like:
1. create keyfile with $ ssh-keygen -t <rsa|dsa>
2. copy the pub file to ...
Thanks!
Use ssh-agent
You then use ssh-add , add your key , enter your password.
As long as your session is open, you then simply
ssh -i ~/.ssh/key user@server
slakkie
May 6th, 2009, 12:31 PM
This is pretty simple to do:
ssh-keygen like you suggested
ssh-copy-id $machine will copy the public key to the remote box and you should have a passwordless connection.
sa125
May 7th, 2009, 04:41 AM
Thanks for all of those - I'll try them and see which one works for me.
lensman3
May 7th, 2009, 11:28 PM
On one line do:
cat ~/.ssh/id_rsa.pub | ssh user@remotebox "(mkdir .ssh&>/dev/null; chmod 700 .ssh && cat - >> .ssh/authorized_keys )&&chmod 600 .ssh/authorized_keys"
Just change the user@romotebox. When you run this it will prompt for the password the first time, because it has to login and append to the authorized_keys file. After that no password required. This little script creates the hidden directories and changes the file permissions to the correct mode. Works fine if the .ssh hidden directory already exists. The only real gotcha is that you must be in the home directory of the user that is being setup. "cd" by itself on a line takes you to your home directory, the tilde's ~.
Setup the RSA encryption as earlier.
ssh-keygen -t rsa
Hope this helps.
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.