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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Depending on your distribution and on the version of ssh-add you may be able or not to use the
-poption of ssh-add that reads the passphrase from stdin in this way: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.The usage is simply:
ssh-add-pass keyfile passfile