sudo cat << EOF > File doesn't work, sudo su does sudo cat << EOF > File doesn't work, sudo su does bash bash

sudo cat << EOF > File doesn't work, sudo su does


Output redirection (e.g., >) is performed by bash, not by cat, while running with your UID. To run with root's UID use sudo:

sudo bash -c 'cat << EOF > /etc/yum.repos.d/some-name.repoline1line2line3EOF'


Another option is tee.

cat << EOF | sudo tee -a /etc/yum.repos.d/some-name.repo...EOF


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.