Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions bin/key2nodes
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,25 @@ while (1) {
stderr_to_stdout => 1,
async => 1,
#tty => 1,
}, 'if [ ! -d ~/.ssh ]; then mkdir ~/.ssh; fi; chmod 700 ~/.ssh; cat >> ~/.ssh/authorized_keys && chmod 640 ~/.ssh/authorized_keys');
}, <<'_EOC_');
read PUBLIC_KEY
if [ ! -d ~/.ssh ]
then
mkdir ~/.ssh
chmod 700 ~/.ssh
fi
if [ ! -f ~/.ssh/authorized_keys ]
then
touch ~/.ssh/authorized_keys
chmod 640 ~/.ssh/authorized_keys
fi
if [ -z "$(grep "$PUBLIC_KEY" ~/.ssh/authorized_keys)" ]
then
echo $PUBLIC_KEY >> ~/.ssh/authorized_keys
else
exit 2
fi
_EOC_
if (!defined $pid or $pid == -1) {
$active_count--;
print "===" x 7, " $host ", "===" x 7, "\n";
Expand Down Expand Up @@ -218,7 +236,13 @@ while (1) {
print;
}
if ($exit > 0) {
warn "Remote command returns status code $exit.\n";
if ($exit == 2) {
if ($verbose) {
warn "Public key is already present.\n";
}
} else {
warn "Remote command returns status code $exit.\n";
}
}
print "\n";
close $in;
Expand Down Expand Up @@ -292,6 +316,8 @@ This script push local F<~/.ssh/id_rsa.pub> file (i.e. the SSH public key) onto

If there's no .ssh directory on the remote server, it will try to create one.

If the key already exists, it is ignored. If the verbose (-v) flag is active a message is displayed.

Note that the sh/bash shell is assumed on the remote machines.

When no F<~/.ssh/id_rsa.pub> file found on the local machine, it will invoke
Expand Down