8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

expectでsshのパスフレーズ付き鍵認証を自動化

Posted at
expect_ssh_key_with_passphrase.sh
#! /bin/bash

host=xxx.xxx.xxx.xxx
login_name=hoge
key=/xxxx/xxxx/xxxx/id_rsa
passphrase=xxxxxxxx

if [ -z `ssh-add -l | grep $key | awk '{print $3}'` ]; then
    expect -c "
    set timeout -1
    spawn ssh-add $key
    expect \"Enter passphrase for $key:\"
    send \"$passphrase\n\"
    interact
    "
fi

ssh -l $login_name -i $key $host
8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?