Well it sounds like you'll want to write a simple loop in bash and use
to replace the vim steps. Cat prints the contents of a file and we can redirect that to write or append to another file. Also before I go on, is there a specific reason for 755 as the permissions on the .ssh directory? Generally you should be using 700 since only that user should have access to sensitive information like that. I'm also confused by what you mean when you say
Quote:
and then adding their ssh keys into their individual .ssh/authorized_keys file
|
are you saying you want a user's own public ssh key in their own authorized_keys file, or are you trying to have some other public keys in each user's authorized_keys? I'm just a little confused by the purpose of the former case. I'll leave the explanation generic and you can adjust it to your needs in any event.
Let's say you have a file called usernames in the current directory with a name on each line. Then your loop could look something like this:
Code:
#!/bin/bash
for user in $( cat ./usernames ); do
mkdir -p /home/$user/.ssh
cat /path/to/pubkey >> /home/$user/.ssh/authorized_keys
chmod 700 /home/$user/.ssh
chmod 644 /home/$user/.ssh/authorized_keys
chown -R $user.$user /home/$user/.ssh
done
Note that you'll probably want the last line to set the ownership. Just replace /path/to/pubkey with whatever public ssh keys you want in the authorized_keys file. The >>
appends output to the target file which is probably desired in this case, but note that there is also > which instead would
overwrite any contents already in the target file.