Handling special characters in password field of sshpass

Manoj picture Manoj · Sep 29, 2014 · Viewed 9.5k times · Source

I have a Python script which uses sshpass for ssh access to a machine

Popen(["sshpass","-p", "test!@#", "ssh", "-o UserKnownHostsFile=/dev/null", "-o StrictHostKeyChecking=no", "[email protected]"])

But due to the presence of special characters in password field this command is throwing some error. Is there a way that I can use password with special characters in sshpass or anything else which can be called from Python?

The error is: bash: !@#": event not found

Answer

Visvendra Singh Rajpoot picture Visvendra Singh Rajpoot · Apr 22, 2016

Escape character worked in my case. Simply use \ character before '!' or other special characters.