In the first example of a
here document, the
redirection is happening as the current account. If you want it to also happen under the effects of
sudo, presumably as root, then you'd would have needed to wrap it in a shell:
Code:
sh -c "cat > /path/to/my/file.conf <<'EoT'
bla
bla bal
bla
EoT
"
But that puts the here document under root as well. If you use the
sudo method, only
tee runs under root and thus the file it writes can be owned by root.