sshd does not pick up authorized keys file when attaching a new /home partition on GCP

Rubique asked:

I need to create a RHEL machine on GCP with separate partitions for /home, /tmp, and /var. If I were installing on a physical machine I would simply partition my disk when I install the OS but I can’t seem to figure this out on a GCP virtual machine. I:

  • instantiated a new RHEL VM on GCP by selecting an existing one and the "create similar" feature
  • created a new disk on GCP with gcloud compute disks create acas-home --size 200 --type pd-ssd
  • attached it to my VM with gcloud compute instances attach-disk <my-vm-name> --disk acas-home
  • formatted it with sudo mkfs.ext4 -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/sdb
  • mounted the new partition just once in a temporary folder and copied the original .ssh folder into to to import the authorized_keys file
  • added the new disk to /etc/fstab with the following line UUID=<MY_UUID_VALUE> /home ext4 discard,defaults,nofail 0 2
  • mounted the disks with sudo mount -a
  • restarted sshd with sudo systemctl restart sshd.service

After this, I cannot ssh into the server. I tried simply deleting the authorized_keys file and creating a new one but nothing would do. I also tried adding another authorized keys file to sshd_config, and populating it, with this line but it would not pick it up either:

AuthorizedKeysFile  .ssh/authorized_keys /etc/ssh/authorized_keys 

What am I doing wrong?

My answer:

You probably forgot to restore the SELinux contexts for your newly created partition.

restorecon -rv /home

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.