aboutsummaryrefslogtreecommitdiff
path: root/ssh-keygen-wrapper
blob: 9e6fd1a54a2c93e45735b662398bd92dfae16785 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
#
# Create a new SSH keypair.
#

# Parameters
BASENAME="`basename $0`"
TYPE="$1"
HANDLE="$2"
OPTS=""

# Check
if [ -z "$HANDLE" ]; then
  echo "usage: $BASENAME <keytype> <handle>"
  echo "resulting key is stored at ~/.ssh/keys/<keytype>/<handle>"
  exit 1
elif [ -e "$HOME/.ssh/keys/$TYPE/$HANDLE" ]; then
  echo "$BASENAME: file already exists: $HOME/.ssh/keys/$TYPE/$HANDLE"
  exit 1
fi

# Handle custom options
if [ "$TYPE" == "rsa" ]; then
  OPTS="-b 4096"
fi

# Dispatch
ssh-keygen -t $TYPE $OPTS -f $HOME/.ssh/keys/$TYPE/$HANDLE -C "$HANDLE"