CentOS my authorized_keys isnt working!

After initially setting up my CentOS boxes, getting everything installed and setup, copying from one server to another etc i like to get my authorized_keys setup from my machine so i don’t need to keep entering the password.
SELinux is turned on by default after your install and for some reason doesn’t come with the authorized_keys configs initially installed.
Previously i’ve spent hours trying to figure out what was wrong with it and then had a ‘aha’ moment and realised it was SELinux that could be stopping it.

You could turn off SELinux but, its there for a reason and to flat out disable it isn’t the best thing to do (even though i know first hand how much of a pain it can be). If you don’t want to learn about SELinux then just disable it and your keys will no work (as long as you have the following security settings in place)

So; first of all make sure you have your .ssh

cd /
mkdir .ssh
chmod 700 .ssh

Copy your public key into .ssh/authorized_keys and then run restorecon -R -v /root/.ssh
restorecon will spit out something like the following

restorecon reset /root/.ssh context unconfined_u:object_r:admin_home_t:s0->unconfined_u:object_r:ssh_home_t:s0
restorecon reset /root/.ssh/authorized_keys context unconfined_u:object_r:admin_home_t:s0->unconfined_u:object_r:ssh_home_t:s0

Now your keyless access should be working fine.