| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
set -euo pipefail |
| 11 |
|
| 12 |
GIT_HOME="/opt/git" |
| 13 |
|
| 14 |
|
| 15 |
if id git &>/dev/null; then |
| 16 |
echo "git user already exists" |
| 17 |
else |
| 18 |
useradd --system --shell /bin/sh --home-dir "$GIT_HOME" --no-create-home git |
| 19 |
echo "Created git user" |
| 20 |
fi |
| 21 |
|
| 22 |
|
| 23 |
usermod --home "$GIT_HOME" --shell /bin/sh git |
| 24 |
|
| 25 |
|
| 26 |
mkdir -p "$GIT_HOME/.ssh" |
| 27 |
touch "$GIT_HOME/.ssh/authorized_keys" |
| 28 |
chmod 700 "$GIT_HOME/.ssh" |
| 29 |
chmod 600 "$GIT_HOME/.ssh/authorized_keys" |
| 30 |
|
| 31 |
|
| 32 |
chown -R git:git "$GIT_HOME" |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
usermod -aG git makenotwork 2>/dev/null || true |
| 37 |
|
| 38 |
|
| 39 |
chmod -R g+rX "$GIT_HOME" |
| 40 |
|
| 41 |
echo "" |
| 42 |
echo "=== Git SSH setup complete ===" |
| 43 |
echo "" |
| 44 |
echo "Next: run setup-ssh-keys.sh to configure sudoers for authorized_keys management" |
| 45 |
|