8/15/2023 0 Comments Ssh copy key fileThat's important, since we don't want $afile to get evaluated until after it's executing on the remote server. Notice the single ticks!Īlso pay special attention to the fact that all these commands are nested inside of single quotes. This will eliminate your pubkey from getting appended multiple times. NOTE: That last bit is to handle the case where you run the above multiple times against the same servers. Sort -u $afile -o $afile - uniquely sorts authorized_keys file and saves it Set a variable, $afile, with the path to authorized_keys fileĬat - > $afile - take input from STDIN and append to authorized_keys file rw- 1 remoteuser remoteuser 771 May 21 23:03 /home/remoteuser/.ssh/authorized_keysĬreate the directory ~/.ssh and ignore warning us if it's already there Set the remote user's umask to 077, this is so that any directories or files we're going to create, will have their permissions set accordingly like so: $ ls -ld ~/.ssh ~/.ssh/authorized_keysĭrwx- 2 remoteuser remoteuser 4096 May 21 22:58 /home/remoteuser/.ssh These are the commands that pssh will run on each server: ' \ '.cmds to add pubkey.' - this is the trickiest part of what's going on, so I'll break this down by itself (see below). -i tells pssh to send any output to STDOUT rather than store it in files (its default behavior).-A tells pssh to ask for your password and then reuse it for all the servers that it connects to.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |