-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle-ssh
More file actions
58 lines (44 loc) · 1.44 KB
/
toggle-ssh
File metadata and controls
58 lines (44 loc) · 1.44 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
set -e
echo "
ℹ️ This script is just made to disable SSH and move the key to a not-so-obvious location.
This is not real security.
You can modify the SSH key backup directory by modifying the SSH_KEY_BAK variable.
"
# Ensure $HOME exists
if [ -z "$HOME" ]; then
echo "❌ HOME variable not set!"
exit 1
fi
# Definitions
SSH_DIR="$HOME/.ssh"
SSH_DIR_BAK="$HOME/.ssh.bak"
SSH_KEY="id_ed25519_github"
disable_ssh() {
echo "ℹ️ Disabling SSH..."
mkdir -p "$SSH_DIR_BAK"
mv -f "$SSH_DIR/$SSH_KEY" "$SSH_DIR_BAK/$SSH_KEY"
mv -f "$SSH_DIR/$SSH_KEY.pub" "$SSH_DIR_BAK/$SSH_KEY.pub"
ssh-add -d "$SSH_DIR_BAK/$SSH_KEY" 2>/dev/null || echo "❌ Key not loaded in ssh-agent"
echo "✅ SSH disabled."
}
enable_ssh() {
echo "ℹ️ Enabling SSH..."
mkdir -p "$SSH_DIR"
mv -f "$SSH_DIR_BAK/$SSH_KEY" "$SSH_DIR/"
mv -f "$SSH_DIR_BAK/$SSH_KEY.pub" "$SSH_DIR/"
chmod 600 "$SSH_DIR/$SSH_KEY" 2>/dev/null || true
chmod 644 "$SSH_DIR/$SSH_KEY.pub" 2>/dev/null || true
ssh-add "$SSH_DIR/$SSH_KEY" || echo "❌ 'ssh-agent' not running"
echo "✅ SSH enabled."
}
# Check private and public keys
if [ -f "$SSH_DIR/$SSH_KEY" ] && [ -f "$SSH_DIR/$SSH_KEY.pub" ]; then
disable_ssh
elif [ -f "$SSH_DIR_BAK/$SSH_KEY" ] && [ -f "$SSH_DIR_BAK/$SSH_KEY.pub" ]; then
enable_ssh
else
echo "❌ Failed to find both private and public SSH keys in '$SSH_DIR' or '$SSH_DIR_BAK'"
echo " ℹ️ Please to something about that"
exit 1
fi