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 '...' >> somefile
withouttouch
directly. To avoid usingchmod
set apropriate right for directory viaumask
orsetfacl
– Costas Jan 20 '15 at 15:37umask
. It is a built-in Bash command, right? Issetfacl
from a different shell? If I want to only setumask
for specific files, I think I should do it as Stéphane described, in a compound command, yes? – amacleod Jan 20 '15 at 16:47umask
yes, the command sets file mode creation mask just for calling process, so see Stéphane's answer. – Costas Jan 20 '15 at 17:03