-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddssh.sh
More file actions
30 lines (25 loc) · 905 Bytes
/
Copy pathaddssh.sh
File metadata and controls
30 lines (25 loc) · 905 Bytes
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
29
30
#!/bin/sh
set -e
username=$1
sshdir="/home/$username/.ssh"
mkdir -p "$sshdir"
# Copy whichever key types are provided in ssh-keys/
cp ./ssh-keys/dev.pem "$sshdir/id_ed25519"
cp ./ssh-keys/dev.pub "$sshdir/id_ed25519.pub"
chmod 600 "$sshdir/id_ed25519"
chmod 644 "$sshdir/id_ed25519.pub"
# Build authorized_keys from all public keys
cat "$sshdir"/*.pub > "$sshdir/authorized_keys" 2>/dev/null || true
chmod 644 "$sshdir/authorized_keys"
chown -R 1000:1000 "$sshdir"
chmod 700 "$sshdir"
# Install persistent SSH host keys (so the fingerprint survives rebuilds)
for keytype in ed25519 rsa ecdsa; do
keyfile="./ssh-keys/ssh_host_${keytype}_key"
if [ -f "$keyfile" ]; then
cp "$keyfile" "/etc/ssh/ssh_host_${keytype}_key"
cp "${keyfile}.pub" "/etc/ssh/ssh_host_${keytype}_key.pub"
chmod 600 "/etc/ssh/ssh_host_${keytype}_key"
chmod 644 "/etc/ssh/ssh_host_${keytype}_key.pub"
fi
done