Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7618687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:28:16+00:00 2026-05-31T03:28:16+00:00

I need to generate an SSH key pair that I’ll be working with later

  • 0

I need to generate an SSH key pair that I’ll be working with later in the program, and therefore need them as strings. Unfortunately, the ssh-keygen utility doesn’t support writing the keys to STDOUT or something the like.

So, the “next best thing” would be to have ssh-keygen write its output to temporary files, which I can then read back into the program. This however poses the risk of somebody else on the system reading the private keyfile (the script will be run by a web app).

How can I generate a key pair in a way that is secure?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:28:18+00:00Added an answer on May 31, 2026 at 3:28 am

    There is no perfectly secure way to generate private keys for distribution; the most secure way is to have each client generate its keypairs and only transmit the public key.

    However, if you’re in a situation where that simply won’t work, and you’re committed to generating keypairs centrally, you do have a few options.

    There are Hardware Security Modules (HSMs) that do this for you. If you can afford it, this is the best way to go.

    Failing that:

    1. Ensure your web-app or the key-generator wrapper runs under its own user (I’ll call this user ‘kguser’ for the rest of this answer).
    2. Make a non-web-accessible directory owned by kguser, with permissions 0700 (set with chmod)
    3. Make sure your key-generator wrapper sets ‘umask 0177’; that should ensure that any files it creates are 0600 (only kguser will be able to read and write)
    4. generate your keys specifying hard-to-guess (e.g. Random UUID) file names
    5. chmod 0600 the key files as soon as you generate them, just in case your umask setting doesn’t hold or gets changed
    6. transmit the private key via an SSL/TLS connection
    7. securely erase the private key file (e.g. ‘shred’ on Linux)
    8. use a cron job to regularly find and securely erase any private key files older than a few minutes (to clean up any files that are left due to an application error, crash, etc.)

    If you’re really paranoid, you can also ensure that the keys are encrypted while on disk by having your web application use its own symmetric key to encrypt on writing and decrypt when sending to the user. However, that opens up more key-management to screw up, so I don’t recommend it.

    Setting a passphrase on the key will help a lot as well, if you never store that passphrase to disk. If someone does manage to recover a passphrase-protected key, they still have to guess the passphrase for the key to be useful. However, this also means your users will have to provide a passphrase when they use the key — this may or may not be acceptable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to generate some passwords, I want to avoid characters that can be
I need to generate thumbnails from a set of jpg's that need to have
I have a working perl script that grabs the data I need and displays
I need to generate real Spotify playlists (not a text string that you can
I need to do the SSH key audit for GitHub, but I am not
I need to generate a loop that would iterate through each capital letter of
We have applications on Solaris 10 servers that generate text logfiles. We need to
I need generate thumbnails for a bunch of jpegs (200,000+) but I want to
I need generate action links outside controllers. I can use Html.Action in Views, Url.Action
I need to generate a random integer between 1 and n (where n is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.