I do not have passwordless ssh enabled between my two servers a and b. So I am using sshpass to connect to the server b from a.
I have a requirement to add host entries in the /etc/hosts of server b from a. But the user that i am logging into server b is non-root user but has sudo privileges to edit files owned by root.
How do i add host entries to /etc/hosts of server b from server a through a shell script while using sshpass.
Here is the script that was tried:
#!/bin/bash
export SSHPASS="password"
SSHUSER=ciuser
WPC_IP=10.8.150.28
sshpass -e ssh -o UserKnownHostsFile=/dev/null -o 'StrictHostKeyChecking no' $SSHUSER@$WPC_IP "echo test >> /etc/hosts"
Output:
bash test.sh
Warning: Permanently added '10.8.150.28' (RSA) to the list of known hosts.
bash: /etc/hosts: Permission denied
Thank you.