Differences between revisions 4 and 5
Revision 4 as of 2007-10-09 21:07:31
Size: 2024
Editor: JariAalto
Comment: Tone down text a bit by removing references of lazy manual page readers
Revision 5 as of 2007-10-10 13:12:34
Size: 1755
Editor: GreyCat
Comment: link to SshKeys which describes the permissions problems in much more detail
Deletions are marked like this. Additions are marked like this.
Line 21: Line 21:
If you're being prompted for a password even with the public key inserted into the remote {{{authorized_keys}}} file, chances are you have a permissions problem on the remote system. Check '''every single directory''' in the full path leading up to the {{{authorized_keys}}} file and make sure they do '''not''' have world- or group-write privileges.  ''E.g.'', if your home directory is {{{/home/fred}}} and {{{/home}}} has group "staff" write privileges, {{{sshd}}} will refuse to honor your key. If you're being prompted for a password even with the public key inserted into the remote {{{authorized_keys}}} file, chances are you have a permissions problem on the remote system. See SshKeys for a discussion of such problems.
Line 25: Line 25:
If you ''really'' want to use a password instead of public keys, first have your head examined. Then, if you ''still'' want to use a password, use [http://expect.nist.gov/ expect(1)]. And don't ask us for help with it. If you ''really'' want to use a password instead of public keys, first have your head examined. Then, if you ''still'' want to use a password, use [http://expect.nist.gov/ expect(1)]. But don't ask us for help with it.

Anchor(faq69)

I want to automate an ssh (or scp, or sftp) connection, but I don't know how to send the password....

STOP!

First of all, if you actually were to embed your password in a script somewhere, it would be visible to the entire world (or at least, anyone who can read files on your system). This would defeat the entire purpose of having a password on your remote account.

If you understand this and still want to continue, then the next thing you need to do is read and understand the man page for ssh-keygen(1). This will tell you how to generate a public/private key pair (in either RSA or DSA format), and how to use these keys to authenticate to the remote system without sending a password at all.

Here is a brief summary of the procedure:

ssh-keygen -t rsa
ssh me@remote "cat >> ~/.ssh/authorized_keys" < ~/.ssh/id_rsa.pub
ssh me@remote date     # should not prompt for passWORD,
                       # but your key may have a passPHRASE

If your key has a passphrase on it, and you want to avoid typing it every time, look into ssh-agent(1). It's beyond the scope of this document, though.

If you're being prompted for a password even with the public key inserted into the remote authorized_keys file, chances are you have a permissions problem on the remote system. See SshKeys for a discussion of such problems.

If that's not it, then make sure you didn't spell it authorised_keys. SSH uses the US spelling, authorized_keys.

If you really want to use a password instead of public keys, first have your head examined. Then, if you still want to use a password, use [http://expect.nist.gov/ expect(1)]. But don't ask us for help with it.

BashFAQ/069 (last edited 2019-04-11 12:53:15 by GreyCat)