Reputation: 1483
I'm trying to have one command line to execute ssh-keygen and generate the keys with no further user input (no passphrase)
I'd expect this to have been enough
expect -d -c "spawn ssh-keygen; expect -re {.*: } { send '\n' }; expect -re {.*: } { send '\n' }; expect -re {.*: } { send '\n' }"
However after the final step, it simply exits.
Attempting one more layer
expect -d -c "spawn ssh-keygen; expect -re {.*: } { send '\n' }; expect -re {.*: } { send '\n' }; expect -re {.*: } { send '\n' }; expect -re {.*: } { send '\n' }"
It complains Saving key "'" failed: passphrase is too short (minimum five characters)
Why does expect ssh-keygen command exits on the first attempt without completing?
Why does ssh-keygen complains that he received "'" when he supposedly received \n?
Upvotes: 1
Views: 301
Reputation: 531045
You don't need expect
for this. Just specify an empty passphrase with the -N
option.
ssh-keygen -f foo -N ''
Upvotes: 2
Reputation: 12255
If you want a one-liner try
expect -c 'spawn ssh-keygen; expect : { send \n; exp_continue} eof'
Strings in expect do not use '
for quoting. You can use ""
or {}
depending on your string. The use of .*
in the pattern serves no real purpose in this example, so you may as well just match on :
. The use of exp_continue
will loop through the same expect statement. eof
matches end of file.
Upvotes: 1