Saturday, 3 September 2016

Automate ssh execution with password auth

Warning: The following command should be used only, operating on hosts not shared with other users, for example in internal test-labs. Otherwise the following command line might leak the password via ps process table to other users. 

In case  to automate ssh commands for example in test-lab and using password authentication instead of public-private authentication the following command options could be used with ssh (sshpass and -o options will work similar for scp).

sshpass -p${PASSWORD} ssh -c arcfour  -o StrictHostKeyChecking=no  -o UserKnownHostsFile=/dev/null -o ControlMaster=no -o LogLevel=ERROR -l ${USER} ${HOST_IP} ${COMMAND}

Explaining a few elements:
  • sshpass is a command feeding the password into ssh via stdin, emulating terminal input.
  • StrictHostKeyChecking=no will disable the lookup of host-key of the target host in local whitelist. In case of freshly added machines to test-lab, the ssh command will not wait for manual confirmation to trust the new remote host.

Using Ubuntu sshpass can be installed as:

sudo apt-get install sshpass

No comments:

Post a Comment