Score:1

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

ke flag

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?

John Hanley avatar
cn flag
Check the ownership and permissions for the directory `~/.ssh` and the file ~/.ssh/authorized_keys`. If the settings are wrong, you cannot log in with that user ID.
Wojtek_B avatar
jp flag
Were you able to solve your issue ? Can you connect via SSH at all ? You may also try [serial console interactive mode](https://cloud.google.com/compute/docs/troubleshooting/troubleshooting-using-serial-console). Have a look at my other answer on [how to connect if you lost access](https://serverfault.com/a/1045717/545593).
Score:0
cz flag

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

restorecon -rv /home
Score:0
dz flag
Pit

Could you please give a try following the official documentation and make the connection through gcloud:

gcloud compute ssh --project=PROJECT_ID --zone=ZONE VM_NAME

You can find more guidance in the official documentation on how to troubleshoot SSH in GCP.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.