How can I use SSH to send multiple commands to a networked system, logging in as root, and providing a password?
I know you can do:
ssh -l <username> target_host
to login, but I’m not sure how to provide the password and a command so it all gets executed in one line. I’m looking to make a script with many one-liner commands to the networked system that can be run as a one-off from another computer.
ssh root@host “command”
ie: ssh root@192.168.1.1 “cat /etc/fstab”
If you are trying to execute multiple commands, I would suggest looking into some form of Expect scripting. I personally am a fan of Pexpect (Python).
Using keys to circumvent password prompt (from man ssh):