Browse Source

ssh: split authorized_keys sanitizer

Signed-off-by: Alejandro Mery <amery@geeks.cl>
master
Alejandro Mery 10 years ago
parent
commit
d334dfc6e6
2 changed files with 50 additions and 44 deletions
  1. +5
    -44
      sync.sh
  2. +45
    -0
      sync_ssh.sh

+ 5
- 44
sync.sh

@ -1,49 +1,10 @@
#!/bin/sh
set -e
cd "files"
find ! -type d -exec ../sync2.sh '{}' \;
keys=
for x in $HOME/.ssh/*.pub; do
if [ -s "$x" ]; then
keys="$keys $x"
else
rm "$x"
fi
done
cd "$(dirname "$0")"
DIR="$PWD"
ak="$HOME/.ssh/authorized_keys"
if [ -s "$ak" ]; then
while read l; do
found=
for k in $keys; do
read l2 < $k || true
if [ "$l" = "$l2" ]; then
found=yes
echo "$l"
break
fi
done
cd "files"
find ! -type d -exec "$DIR/sync2.sh" '{}' \;
if [ -z "$found" ]; then
name="$(echo "$l" | cut -d' ' -f3)"
if [ -n "$name" ]; then
echo "$l" > .ssh/$name.pub
fi
fi
done < $ak > $ak~
else
touch $ak
for x in amery@geeks.cl \
amery@builder.geeks.cl \
amery@shell.easy-cloud.net; do
cat .ssh/$x.pub
done > $ak~
fi
if ! cmp $ak $ak~; then
diff -u $ak $ak~ || true
mv $ak~ $ak
fi
cd ..
git status --porcelain
exec "$DIR/sync_ssh.sh"

+ 45
- 0
sync_ssh.sh

@ -0,0 +1,45 @@
#!/bin/sh
keys=
for x in $HOME/.ssh/*.pub; do
if [ -s "$x" ]; then
keys="$keys $x"
else
rm "$x"
fi
done
ak="$HOME/.ssh/authorized_keys"
if [ -s "$ak" ]; then
while read l; do
found=
for k in $keys; do
read l2 < $k || true
if [ "$l" = "$l2" ]; then
found=yes
echo "$l"
break
fi
done
if [ -z "$found" ]; then
name="$(echo "$l" | cut -d' ' -f3)"
if [ -n "$name" ]; then
echo "$l" > .ssh/$name.pub
fi
fi
done < $ak > $ak~
else
touch $ak
for x in amery@geeks.cl \
amery@builder.geeks.cl \
amery@shell.easy-cloud.net; do
x="$HOME/.ssh/$x.pub"
[ -s "$x" ] || continue
cat "$x"
done > $ak~
fi
if ! cmp $ak $ak~; then
diff -u $ak $ak~ || true
mv $ak~ $ak
fi

Loading…
Cancel
Save