The PuTTYgen program is part of PuTTY, an open source networking client for the Windows platform.
In case you travel and can’t carry your laptop with you, just keep your private key on a USB stick and attach it to your physical keychain. Your server will be much safer this way. Generate Public/Private SSH Key Pair. Open Command Prompt from the Start Menu and type. The simplest way to generate a key pair is to run ssh-keygen without arguments. In this case, it will prompt for the file in which to store keys. Here's an example: klar (11:39) ssh-keygen Generating public/private rsa key pair. Generate online private and public key for ssh, putty, github, bitbucket Save both of keys on your computer (text file, dropbox, evernote etc)!!! The generated keys are RANDOM and CAN'T be restored.
- Download and install PuTTY or PuTTYgen.
To download PuTTY or PuTTYgen, go to http://www.putty.org/ and click the You can download PuTTY here link.
- Run the PuTTYgen program.
- Set the Type of key to generate option to SSH-2 RSA.
- In the Number of bits in a generated key box, enter 2048.
- Click Generate to generate a public/private key pair.
As the key is being generated, move the mouse around the blank area as directed.
- (Optional) Enter a passphrase for the private key in the Key passphrase box and reenter it in the Confirm passphrase box.
Note:
While a passphrase is not required, you should specify one as a security measure to protect the private key from unauthorized use. When you specify a passphrase, a user must enter the passphrase every time the private key is used.
- Click Save private key to save the private key to a file. To adhere to file-naming conventions, you should give the private key file an extension of
.ppk(PuTTY private key).Note:
The.ppkfile extension indicates that the private key is in PuTTY's proprietary format. You must use a key of this format when using PuTTY as your SSH client. It cannot be used with other SSH client tools. Refer to the PuTTY documentation to convert a private key in this format to a different format. - Select all of the characters in the Public key for pasting into OpenSSH authorized_keys file box.
Make sure you select all the characters, not just the ones you can see in the narrow window. If a scroll bar is next to the characters, you aren't seeing all the characters.
- Right-click somewhere in the selected text and select Copy from the menu.
- Open a text editor and paste the characters, just as you copied them. Start at the first character in the text editor, and do not insert any line breaks.
- Save the text file in the same folder where you saved the private key, using the
.pubextension to indicate that the file contains a public key. - If you or others are going to use an SSH client that requires the OpenSSH format for private keys (such as the
sshutility on Linux), export the private key:- On the Conversions menu, choose Export OpenSSH key.
- Save the private key in OpenSSH format in the same folder where you saved the private key in
.ppkformat, using an extension such as.opensshto indicate the file's content.
- This module allows one to (re)generate OpenSSH private and public keys. It uses ssh-keygen to generate keys. One can generate
rsa,dsa,rsa1,ed25519orecdsaprivate keys.


The below requirements are needed on the host that executes this module.
- ssh-keygen
| Parameter | Choices/Defaults | Comments |
|---|---|---|
| attributes string | The attributes the resulting file or directory should have. To get supported flags look at the man page for chattr on the target system. This string should contain the attributes in the same order as the one displayed by lsattr. The = operator is assumed as default, otherwise + or - operators need to be included in the string. | |
| comment added in 2.9 | Provides a new comment to the public key. When checking if the key is in the correct state this will be ignored. | |
| force boolean |
| Should the key be regenerated even if it already exists |
| group string | Name of the group that should own the file/directory, as would be fed to chown. | |
| mode string | The permissions the resulting file or directory should have. For those used to /usr/bin/chmod remember that modes are actually octal numbers. You must either add a leading zero so that Ansible's YAML parser knows it is an octal number (like 0644 or 01777) or quote it (like '644' or '1777') so Ansible receives a string and can do its own conversion from string into number.Giving Ansible a number without following one of these rules will end up with a decimal number which will have unexpected results. As of Ansible 1.8, the mode may be specified as a symbolic mode (for example, u+rwx or u=rw,g=r,o=r).As of Ansible 2.6, the mode may also be the special string preserve.When set to preserve the file will be given the same permissions as the source file. | |
| owner string | Name of the user that should own the file/directory, as would be fed to chown. | |
| path path / required | Name of the files containing the public and private key. The file containing the public key will have the extension .pub. | |
| selevel string | Default: | The level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the range.When set to _default, it will use the level portion of the policy if available. |
| serole string | When set to _default, it will use the role portion of the policy if available. | |
| setype string | When set to _default, it will use the type portion of the policy if available. | |
| seuser string | By default it uses the system policy, where applicable.When set to _default, it will use the user portion of the policy if available. | |
| size integer | Specifies the number of bits in the private key to create. For RSA keys, the minimum size is 1024 bits and the default is 4096 bits. Generally, 2048 bits is considered sufficient. DSA keys must be exactly 1024 bits as specified by FIPS 186-2. For ECDSA keys, size determines the key length by selecting from one of three elliptic curve sizes: 256, 384 or 521 bits. Attempting to use bit lengths other than these three values for ECDSA keys will cause this module to fail. Ed25519 keys have a fixed length and the size will be ignored. | |
| state string |
| Whether the private and public keys should exist or not, taking action if the state is different from what is stated. |
| type string |
| The algorithm used to generate the SSH private key. rsa1 is for protocol version 1. rsa1 is deprecated and may not be supported by every version of ssh-keygen. |
| unsafe_writes boolean |
| Influence when to use atomic operation to prevent data corruption or inconsistent reads from the target file. By default this module uses atomic operations to prevent data corruption or inconsistent reads from the target files, but sometimes systems are configured or just broken in ways that prevent this. One example is docker mounted files, which cannot be updated atomically from inside the container and can only be written in an unsafe manner. This option allows Ansible to fall back to unsafe methods of updating files when atomic operations fail (however, it doesn't force Ansible to perform unsafe writes). IMPORTANT! Unsafe writes are subject to race conditions and can lead to data corruption. |
Common return values are documented here, the following are the fields unique to this module:
| Key | Returned | Description |
|---|---|---|
| comment string | changed or success | Sample: |
| filename | changed or success | Path to the generated SSH private key file /tmp/id_ssh_rsa |
| fingerprint string | changed or success | Sample: SHA256:r4YCZxihVjedH2OlfjVGI6Y5xAYtdCwk8VxKyzVyYfM |
| public_key string | changed or success | Sample: ssh-rsa AAAAB3Nza(...omitted...)veL4E3Xcw test_key |
| size integer | changed or success | Sample: |
| type | changed or success | Algorithm used to generate the SSH private key rsa |
- This module is not guaranteed to have a backwards compatible interface. [preview]
- This module is maintained by the Ansible Community. [community]
Ssh Public And Private Key
Authors¶
- David Kainz (@lolcube)
Hint
Create Ssh Private Key
If you notice any issues in this documentation, you can edit this document to improve it.