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

  • Home
  • SEARCH
  • 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 8715375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:49:41+00:00 2026-06-13T05:49:41+00:00

I am trying to add a key to ssh-agent and want ssh-add to read

  • 0

I am trying to add a key to ssh-agent and want ssh-add to read the password from the key file I’m using. How is this possible?

How do I automate this process from the shell script?

  • 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-06-13T05:49:44+00:00Added an answer on June 13, 2026 at 5:49 am

    Depending on your distribution and on the version of ssh-add you may be able or not to use the -p option of ssh-add that reads the passphrase from stdin in this way:

    cat passfile | ssh-add -p keyfile
    

    If this is not working you can use Expect, a Unix tool to make interactive applications non-interactive. You’ll have to install it from your package manager.

    I have written a tool for you in expect. Just copy the content in a file named ssh-add-pass and set executable permissions on it (chmod +x ssh-add-pass). You can also copy it to /usr/bin or /usr/local/bin to be accessible from the $PATH search.

    #!/bin/bash
    
    if [ $# -ne 2 ] ; then
      echo "Usage: ssh-add-pass keyfile passfile"
      exit 1
    fi
    
    eval $(ssh-agent)
    pass=$(cat $2)
    
    expect << EOF
      spawn ssh-add $1
      expect "Enter passphrase"
      send "$pass\r"
      expect eof
    EOF
    

    The usage is simply: ssh-add-pass keyfile passfile

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

Sidebar

Related Questions

Please add an SSH key before provisioning a machine. I am trying to create
I'm trying to add some additional key/value pairs to an NSMutableDictionary, using: Tag *tag1
I m trying to add a foreign key to table table2 from table1 .
I'm getting this error when trying to add a foreign key contraint: #1005 -
I am trying to add key bindings to the .screenrc file for making a
I am trying to add the key values from a Treemap to a String[],
I am trying to add a foreign key using MySQL Workbench. I created a
I am trying to add a key from one table to another so that
This is killing me... When trying to add a key to like so: category.site_ids
I am trying to SCP a file from my application to a server using

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.