-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sh
executable file
·36 lines (30 loc) · 1.02 KB
/
script.sh
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
IP=10.60.3.1
EMAIL="[email protected]"
echo "the target IP is: $IP"
ssh-keygen -R $IP
# Set the SSH key file path
SSH_KEY="$HOME/.ssh/id_ed25519"
# Check if the SSH key exists
if [ -f "$SSH_KEY" ]; then
echo "SSH key already exists at $SSH_KEY, adding to the server"
scp root@$IP:/root/.ssh/authorized_keys .
cat ~/.ssh/id_ed25519.pub >> authorized_keys
scp authorized_keys root@$IP:/root/.ssh/
else
echo "SSH key does not exist. Creating a new SSH key..."
# Generate a new SSH key
ssh-keygen -t ed25519 -C $EMAIL -f "$SSH_KEY" -N ""
# Check if the key was successfully created
if [ -f "$SSH_KEY" ]; then
echo "New SSH key created successfully at $SSH_KEY, adding to the server"
scp root@$IP:/root/.ssh/authorized_keys .
cat ~/.ssh/id_ed25519.pub >> authorized_keys
scp authorized_keys root@$IP:/root/.ssh/
else
echo "Failed to create a new SSH key."
fi
fi
echo "Cloning server directories"
mkdir bck
cd bck
rsync -avhP root@$IP:/root/ .