11

I need to automate some identity deployments, ideally using ssh-copy-id.

I'm trying to provide the password through stdin, which is possible on ssh by using the -S flag. I'm aware that I can send additional options to ssh using the -o flag in the ssh-copy-id command however there's no usage examples of this flag in the man page.

So I've tried to pass the SSH password for ssh-copy-id through stdin using:

$# echo $TMP_PASS | ssh-copy-id -p2222 -i key.pub user@host -o "-S"

But all I get is:

/bin/ssh-copy-id: ERROR: command-line: line 0: Bad configuration option: -s

EDIT:

I'm trying to provide the password through stdin, which is possible on ssh by using the -S flag.

This statement is wrong. I've actually read this flag from sudo man;

15

You might want to try installing sshpass, and altering your call to ssh-copy-id:

sshpass -p "$TMP_PASS" ssh-copy-id
| improve this answer | |
  • lol, not on mac and when brew install is attempted, i get "Error: No available formula with the name "sshpass" We won't add sshpass because it makes it too easy for novice SSH users to ruin SSH's security." – tofutim Apr 13 '18 at 19:26
  • There are instructions to install it with homebrew on osx here gist.github.com/arunoda/7790979#installing-with-homebrew You would just need to run brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb – ewatt Oct 6 '18 at 21:49
2

Where did you find the information about -S option? It does something completely different! It is used for multiplexing and ControlPath.

SSH will not accept passwords on stdin ever, so you should pre-install authorized keys in your deployment (preferred way) or use sshpass or expect script as described in many other questions.

| improve this answer | |
  • Damn you're right! I've just realized that -S flag is from sudo :S – kbtz Sep 16 '15 at 15:09
  • If I want to install my keys on 100 hosts, using ssh-copy-id, having that all the hosts already have a default username and password, how to avoid ssh-copy-id asking me every time the same password? – realtebo Aug 11 '18 at 15:08
  • That is already answered in both of the answers -- use sshpass if you have to or some expect script. – Jakuje Aug 13 '18 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.