I want to speed up creation of user accounts on some Linux VMs that I am creating, and wondered if I could simplify the process of writing to the new user's ~/.ssh/authorized_keys or ~/.ssh/authorized_keys2 file.
My manual process is, approximately (logged in as the new user):
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
touch ~/.ssh/authorized_keys
chmod go-rwx ~/.ssh/authorized_keys
echo '... me@machine' >> ~/.ssh/authorized_keys
Is there any way, with a Bash command, a standard GNU command, or any program easily installed on Ubuntu, to condense the touch, chmod, and echo into one command?
Part of the reason I would like to reduce it to one command is so that I can make a shell script that I can run as the initial sudo-capable user on the VM.
Something like:
sudo su - me -c 'ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa'
echo '... me@machine' | sudo su - me -c 'xyz 0600 ~/.ssh/authorized_keys'
Where xyz is the hypothetical command that creates, sets permissions, and writes the file all in one fell swoop.
echo '...' >> somefilewithouttouchdirectly. To avoid usingchmodset apropriate right for directory viaumaskorsetfaclumask. It is a built-in Bash command, right? Issetfaclfrom a different shell? If I want to only setumaskfor specific files, I think I should do it as Stéphane described, in a compound command, yes?