I know the title is just baiting the "your setup is insecure", but allow me to explain.
I'm working on an application which aims to allow clients to rsync over SSH to our server. We need a web application from which we can create/rotate SSH keys for our users. This application will return a private SSH key to the user for their future use and will store the public key user's authorized_keys file.
Upon registration, we'll need to automatically create the user and initial .ssh directory and keys.
We're on CentOS 5 now, but we're flexible if there's sufficient reason to migrate. This server will be running only this web application in Apache (as apache:apache) and no data other than the synchronized user data will be stored on the system.
I've been thinking about the following solution, but have been running into trouble:
- Grant sudo
useradd
privileges to the apache user to allow them to create new users - Call
sudo useradd
from the PHP script in the web application with a umask of 000 on the newly created home directory. chgrp
the new home directory toapache
so that apache will be able to create a new .ssh directory and write the keys.*chmod
the new home directory to 770 so that only the user and apache have access.*mkdir .ssh
in the new home directory andssh-keygen
to create the new key, storing the public key inauthorized_keys
and passing the private key back to the calling client.
The problems I'm encountering are with the *d points -- it seems that, even with chmod 777 I'm not able to chgrp
or chmod
the directory, as it's been created with the owner and group belonging to the new user.
I've looked at changing the user's default group to something that would allow apache to write to it, but I can't find a way to do that without having to grant apache usermod
sudo privileges, which seems like a really bad idea.
Any thoughts would be appreciated!