correct perms on .ssh
[webi-installers/.git] / ssh-utils / ssh-pubkey.sh
1 #!/bin/bash
2
3 {
4     set -e
5     set -u
6
7     if [ ! -d "$HOME/.ssh" ]; then
8         mkdir -p "$HOME/.ssh/"
9         chmod 0700 "$HOME/.ssh/"
10     fi
11
12     if [ ! -f "$HOME/.ssh/id_rsa" ]; then
13         ssh-keygen -b 2048 -t rsa -f "$HOME/.ssh/id_rsa" -q -N ""
14         echo ""
15     fi
16
17     if [ ! -f "$HOME/.ssh/id_rsa.pub" ]; then
18         ssh-keygen -y -f "$HOME/.ssh/id_rsa" > "$HOME/.ssh/id_rsa.pub"
19         echo ""
20     fi
21
22     # TODO use the comment (if any) for the name of the file
23     echo ""
24     echo "~/Downloads/id_rsa.$(whoami).pub":
25     echo ""
26     rm -f "$HOME/Downloads/id_rsa.$(whoami).pub":
27     cp -r "$HOME/.ssh/id_rsa.pub" "$HOME/Downloads/id_rsa.$(whoami).pub"
28     cat "$HOME/Downloads/id_rsa.$(whoami).pub"
29     echo ""
30 }