<p>First you need to install <a href="http://sourceforge.net/projects/sshpass/" rel="nofollow noreferrer">sshpass</a>.</p>

<ul>
<li>Ubuntu/Debian: <code>apt-get install sshpass</code>  </li>
<li>Fedora/CentOS: <code>yum install sshpass</code>  </li>
</ul>

<hr>

<p><strong>Example:</strong></p>



<pre class="lang-none prettyprint-override"><code>sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM
</code></pre>

<p><strong>Custom port example:</strong></p>

<pre class="lang-none prettyprint-override"><code>sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM:2400
</code></pre>

<p><strong>Notes:</strong></p>

<ul>
<li><code>sshpass</code> can also read a password from a file when the <code>-f</code> flag is passed.

<ul>
<li>Using <code>-f</code> prevents the password from being visible if the <code>ps</code> command is executed.</li>
<li>The file that the password is stored in should have secure permissions.</li>
</ul></li>
</ul>

CC BY-SA 4.0
2019-05-02T05:06:24.720Z
2019-05-02T05:17:39.050Z
2019-05-02T05:17:39.050Z
Subhash
<p>But storeing your password in a command is not the best way - it should be better to remove the password for this case - so you do not reveal your key password</p>

<pre><code>$ ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
</code></pre>

CC BY-SA 4.0
2019-05-03T11:00:22.807Z
2019-05-03T11:00:22.807Z
Martin Zeug
<p>If you use password-protected SSH keys, is there a way to pass the password at the command line automatically instead of manually typing it?</p>

<p>E.g. something like:</p>

<p><code>ssh-add &lt;key&gt; -p password</code></p>

<jenkins>
Using password protected ssh keys
Olegzandr Denman
# Using password protected ssh keys

(Asked by: username_0 on 2019-05-01)

If you use password-protected SSH keys, is there a way to pass the password at the command line automatically instead of manually typing it?

E.g. something like:

`ssh-add  -p password`

**Tags:** jenkins


---

## 2 answers

### Answer by username_1 on 2019-05-02. Score: 1

First you need to install sshpass.

Ubuntu/Debian: apt-get install sshpass 
Fedora/CentOS: yum install sshpass 


Example:
sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM

Custom port example:
sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM:2400

Notes:

sshpass can also read a password from a file when the -f flag is passed.


Using -f prevents the password from being visible if the ps command is executed.
The file that the password is stored in should have secure permissions.


---

### Answer by username_2 on 2019-05-03. Score: 0

But storeing your password in a command is not the best way - it should be better to remove the password for this case - so you do not reveal your key password
$ ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]


---

