sudo cat << EOF > File doesn't work, sudo su does
As a variation to @Yuriy Nazarov's answer, only the piped output needs to be elevated thru sudo
. The piped input can stay un-elevated:
sudo bash -c 'cat > /etc/yum.repos.d/some-name.repo' << EOFline1line2line3EOF
This means a much smaller portion of the command needs to be quoted and sent thru to sudo
.