0

need add string to file on remote ssh server without prompting sudo password

myuser=testuser

$ sshpass -p "$mypass" ssh -t -o StrictHostKeycheking=no $myuser@$myhost "echo $mypass | sudo -S -s /bin/bash -c \"echo $myText >> test.txt\""

sometimes it gives me

[sudo] password for testuser: /bin/bash: line 1: test.txt: No such file or directory
2
  • Why do you need sudo? Don't you have write access to your home directory? Anyways, you might try with sudo tee test.txt <<< "$myText" or write to /tmp and sudo mv to the final destination. You should review your workflow, this is a security nightmare. Commented Mar 2, 2023 at 13:29
  • it's not my server. test.txt file path is different for example /root/test.txt Commented Mar 3, 2023 at 9:03

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.