0 votesby user188654written 2016-04-26last updated 2017-05-23
heemayl already explained the permission issues however you need to take into account that running sudo commands will still require you to enter the user password manually. That is unless you have specified in the sudoers file that the user running sudo doesn't require a password which I hope is not the case.
So in order to avoid entering the password manually you have a couple of possibilities of which almost all are a pretty bad idea since they basically require of you to store your user password outside the regular /etc/shadow file.
The best you could probably do is store your password inside a plain file and heavily restrict access to it with permissions.
echo "password" > ~/.password && chmod 400 ~/.password
After that you can use the -S parameter for sudo to read the password from an external file like this.
sudo -S bash -c 'echo "some text" > /etc/test' <~/.password
Once again, storing user passwords outside /etc/shadow is a huge security risk, especially if the user has sudoer privileges so I would advise against this approach even if it provides some basic protection.