Found this via google but lost link
I figured out a workaround for this (for all you kids googling this issue out there) but I doubt it is secure, but I am running it for testing scripts from PHP in a virtual environment so that doesn’t matter to me.
Since the APACHE user’s home is “/var/www” and ssh-keygen requires access to /var/www/.ssh but cannot create it because there is no shell you can do the following.
chown -R apache:nobody /var/www/.ssh
sudo -u apache ssh-keygen -t rsa
For ssh-keygen just press enter if you want to test otherwise fill in some values to secure your stuff!
sudo -u apache ssh-copy-id -i /var/www/.ssh/whatever.pub root@host
And you are done!
Remember that if user has no $HOME like nobody has, $HOME will be / and .ssh is expected to be there!!!!