public_key » Revisions »
Differences
This shows you the differences between the selected revisions of the page.
public_key 2007-07-11 | public_key 2023-08-01 (current) | ||
Line 1: | Line 1: | ||
====== Using Public Keys for Authentication ====== | ====== Using Public Keys for Authentication ====== | ||
+ | //This article explains public key authentication in general. You may want to see the guide to [[guide_public_key|setting up public-key authentication]] instead.// | ||
+ | |||
+ | //Do not confuse your user key pair used for authentication with [[ssh_verifying_the_host_key|host public key verification]]. Learn about [[ssh_keys|all SSH key types]].// | ||
===== Introduction ===== | ===== Introduction ===== | ||
Line 7: | Line 10: | ||
In conventional password authentication, you prove you are who you claim to be by proving that you know the correct password. The only way to prove you know the password is to tell the server what you think the password is. This means that if the server has been hacked, or spoofed, an attacker can learn your password. | In conventional password authentication, you prove you are who you claim to be by proving that you know the correct password. The only way to prove you know the password is to tell the server what you think the password is. This means that if the server has been hacked, or spoofed, an attacker can learn your password. | ||
- | Public key authentication solves this problem. You [[public_key#generate|generate a key pair]], consisting of a public key (which everybody is allowed to know) and a private key (which you keep secret and do not give to anybody). The private key is able to generate signatures. A signature created using your private key cannot be forged by anybody who does not have that key; but anybody who has your public key can verify that a particular signature is genuine. | + | Public key authentication solves this problem. You [[#generate|generate a key pair]], consisting of a public key (which everybody is allowed to know) and a private key (which you keep secret and do not give to anybody). The private key is able to generate signatures. A signature created using your private key cannot be forged by anybody who does not have that key; but anybody who has your public key can verify that a particular signature is genuine. |
- | So you generate a key pair on your own computer, and you copy the public key as a single line to a server file called authorized_keys in a folder .ssh which you create in your user root folder, chmodding .ssh to 700 and the file to 600. The sshd_config file (typically in /etc/ssh) will also need these three settings: RSAAuthentication yes, PubkeyAuthentication yes, and AuthorizedKeysFile .ssh/authorized_keys. Then, when the server asks you to prove who you are, WinSCP can generate a signature using your private key. The server can verify that signature (since it has your public key) and allow you to log in. Now if the server is hacked or spoofed, the attacker does not gain your private key or password; they only gain one signature. And signatures cannot be re-used, so they have gained nothing. | + | So you generate a key pair on your own computer, and you copy the public key to the server under a certain name. Then, when the server asks you to prove who you are, WinSCP can generate a signature using your private key. The server can verify that signature (since it has your public key) and allow you to log in. Now if the server is hacked or spoofed, the attacker does not gain your private key or password; they only gain one signature. And signatures cannot be re-used, so they have gained nothing. |
- | There is a problem with this: if your [[public_key#private|private key]] is stored unprotected on your own computer, then anybody who gains access to that will be able to generate signatures as if they were you. So they will be able to log in to your server under your account. For this reason, your private key is usually encrypted when it is stored on your local machine, using a passphrase of your choice. In order to generate a signature, WinSCP must decrypt the key, so you have to type your passphrase.· | + | There is a problem with this: if your [[#private|private key]] is stored unprotected on your own computer, then anybody who gains access to that will be able to generate signatures as if they were you. So they will be able to log in to your server under your account. For this reason, your private key is usually encrypted when it is stored on your local machine, using a passphrase of your choice. In order to generate a signature, WinSCP must decrypt the key, so you have to type your passphrase. |
- | This can make public-key authentication less convenient than password authentication: every time you log in to the server, instead of typing a short password, you have to type a longer passphrase. One solution to this is to use an authentication agent, a separate program which holds decrypted private keys and generates signatures on request. WinSCP can use PuTTY's authentication agent, called [[&pageanthelp|Pageant]]. When you begin a Windows session, you start Pageant and load your private key into it (typing your passphrase once). For the rest of your session, you can start WinSCP any number of times and Pageant will automatically generate signatures without you having to do anything. When you close your Windows session, Pageant shuts down, without ever having stored your decrypted private key on disk. Many people feel this is a good compromise between security and convenience. | + | This can make public-key authentication less convenient than password authentication: every time you log in to the server, instead of typing a short password, you have to type a longer passphrase. One solution to this is to use an authentication agent, a separate program which holds decrypted private keys and generates signatures on request. WinSCP can use PuTTY's authentication agent, called [[ui_pageant|Pageant]]. When you begin a Windows session, you start Pageant and load your private key into it (typing your passphrase once). For the rest of your session, you can start WinSCP any number of times and Pageant will automatically generate signatures without you having to do anything. When you close your Windows session, Pageant shuts down, without ever having stored your decrypted private key on disk. Many people feel this is a good compromise between security and convenience. |
- | There is more than one public-key algorithm available. The most common is RSA, but others exist, notably DSA (otherwise known as DSS), the USA's federal Digital Signature Standard. ((&puttydoccite)) | + | There is more than one public-key algorithm available. The most common are RSA and ECDSA, but others exist, notably DSA (otherwise known as DSS), the USA's federal Digital Signature Standard. ((&puttydoccite)) |
===== [[generate]] Generating Keys ===== | ===== [[generate]] Generating Keys ===== | ||
- | To generate a key pair, use the [[&puttygenhelp|PuTTYgen]] application. Find link to download the program in the [[&download|Download]]. | + | To generate a key pair, use the [[ui_puttygen|PuTTYgen]] application. |
+ | |||
+ | You can start PuTTYgen directly from [[ui_login_authentication|Authentication page]] of Advanced Site Settings dialog. If you start PuTTYgen this way, WinSCP will automatically pick up the generated key. | ||
===== [[private]] Private Keys ===== | ===== [[private]] Private Keys ===== | ||
- | Different file formats are used to store SSH-1 and SSH-2 private keys. While there is only one commonly used format for SSH-1 keys, there are several formats used for SSH-2 keys. WinSCP supports PuTTY format, as authors of PuTTY [[&url(keyformat)|claim that it is the best one]]. | + | Different file formats are used to store SSH private keys. WinSCP supports PuTTY format, as authors of PuTTY [[&url(keyformat)|claim that it is the best one]]. |
- | WinSCP also recognises (but does not accept) the other two formats (OpenSSH and ssh.com), so it can suggest you to convert them. To convert the key file use [[&puttygenhelp|PuTTYgen]] application. | + | WinSCP also recognizes (but does not accept) the other two formats (OpenSSH and ssh.com), and it can convert the keys to PuTTY format for you. To convert the key file you can also use ''[[commandline#keygen|/keygen]]'' command-line switch or [[ui_puttygen|PuTTYgen]] application. |