Last active
May 1, 2025 23:06
-
-
Save yogithesymbian/7f9bea18253abd99dddae1aa6370eb90 to your computer and use it in GitHub Desktop.
script-setup-github-auto V1 | multi account
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 🎨 Warna | |
GREEN='\033[0;32m' | |
BLUE='\033[0;34m' | |
YELLOW='\033[1;33m' | |
NC='\033[0m' # No Color | |
echo -e "${BLUE}=== Setup Akun GitHub dengan SSH dan Git Identity ===${NC}" | |
# 1. Ambil input dari user | |
read -rp "🔹 Masukkan alias SSH (contoh: github.com-personal): " SSH_ALIAS | |
read -rp "🔹 Masukkan email GitHub: " EMAIL | |
read -rp "🔹 Masukkan nama yang akan tampil di commit: " GIT_NAME | |
read -rp "🔹 Masukkan nama file SSH key (contoh: id_ed25519_github_personal): " SSH_KEY_NAME | |
KEY_PATH="$HOME/.ssh/$SSH_KEY_NAME" | |
# 2. Cek jika key sudah ada | |
if [[ -f "$KEY_PATH" ]]; then | |
echo -e "${YELLOW}⚠️ SSH key '$SSH_KEY_NAME' sudah ada. Lewati pembuatan key.${NC}" | |
else | |
echo -e "${BLUE}[1/5] Membuat SSH key baru...${NC}" | |
ssh-keygen -t ed25519 -C "$EMAIL" -f "$KEY_PATH" | |
fi | |
# 3. Tambahkan ke ssh-agent | |
echo -e "${BLUE}[2/5] Menambahkan ke ssh-agent...${NC}" | |
eval "$(ssh-agent -s)" | |
ssh-add "$KEY_PATH" | |
# 4. Update ~/.ssh/config jika belum ada alias | |
if grep -q "Host $SSH_ALIAS" "$HOME/.ssh/config"; then | |
echo -e "${YELLOW}⚠️ Alias $SSH_ALIAS sudah ada di ~/.ssh/config. Lewati penambahan.${NC}" | |
else | |
echo -e "${BLUE}[3/5] Menambahkan alias ke ~/.ssh/config...${NC}" | |
cat <<EOF >> ~/.ssh/config | |
# GitHub - $SSH_ALIAS | |
Host $SSH_ALIAS | |
HostName github.com | |
User git | |
IdentityFile $KEY_PATH | |
IdentitiesOnly yes | |
EOF | |
fi | |
# 5. Tampilkan public key | |
echo -e "${BLUE}[4/5] Berikut public key-nya (salin ke GitHub > SSH Keys):${NC}" | |
echo -e "${GREEN}----------------------------------------------" | |
cat "$KEY_PATH.pub" | |
echo -e "----------------------------------------------${NC}" | |
# 6. Tanya apakah ingin set git user di repo saat ini | |
read -rp "🔸 Mau set git user.name & user.email di repo saat ini? (y/n): " SET_GIT | |
if [[ "$SET_GIT" == "y" || "$SET_GIT" == "Y" ]]; then | |
git config user.name "$GIT_NAME" | |
git config user.email "$EMAIL" | |
echo -e "${GREEN}✅ Git identity diset untuk repo ini.${NC}" | |
else | |
echo -e "${YELLOW}ℹ️ Lewati pengaturan git identity lokal.${NC}" | |
fi | |
# 7. Saran clone URL | |
echo -e "${BLUE}✅ Selesai! Gunakan SSH alias saat clone repo GitHub:${NC}" | |
echo -e "${GREEN}git@${SSH_ALIAS}:USERNAME/NAMA_REPO.git${NC}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment