Skip to content

Commit e50de21

Browse files
committed
feat: only use latest key in known_hosts
1 parent 332a0d6 commit e50de21

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

command-ctrl.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
#!/bin/sh
22

3+
remove_ssh_entry() {
4+
HOST=$1
5+
SSH_FILE=$2
6+
#Remove the entry in both .ssh dirs since ssh checks different locations based on env variables and how it is launched, e.g. on boot vs. manually
7+
for DIR in ~root/.ssh $HOME/.ssh
8+
do
9+
if [ -f "$DIR/$SSH_FILE" ]; then
10+
sed -i "/$HOST/d" "$DIR/$SSH_FILE" 2>&1 >/dev/null
11+
fi
12+
done
13+
}
14+
315
add_ssh_entry() {
416
ENTRY=$1
517
SSH_FILE=$2
@@ -53,6 +65,7 @@ remote_ctrl() {
5365
echo "\$SSH_HOST_KEY is empty"
5466
else
5567
KNOWN_HOST="$SSH_HOST $SSH_HOST_KEY"
68+
remove_ssh_entry "$SSH_HOST" known_hosts
5669
add_ssh_entry "$KNOWN_HOST" known_hosts
5770
fi
5871

vendors/tektelic/command-ctrl.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
#!/bin/sh
22

3+
remove_ssh_entry() {
4+
HOST=$1
5+
SSH_FILE=$2
6+
#Remove the entry in both .ssh dirs since ssh checks different locations based on env variables and how it is launched, e.g. on boot vs. manually
7+
for DIR in ~root/.ssh $HOME/.ssh
8+
do
9+
if [ -f "$DIR/$SSH_FILE" ]; then
10+
sed -i "/$HOST/d" "$DIR/$SSH_FILE" 2>&1 >/dev/null
11+
fi
12+
done
13+
}
14+
315
add_ssh_entry() {
416
ENTRY=$1
517
SSH_FILE=$2
@@ -53,6 +65,7 @@ remote_ctrl() {
5365
echo "\$SSH_HOST_KEY is empty"
5466
else
5567
KNOWN_HOST="$SSH_HOST $SSH_HOST_KEY"
68+
remove_ssh_entry "$SSH_HOST" known_hosts
5669
add_ssh_entry "$KNOWN_HOST" known_hosts
5770
fi
5871

0 commit comments

Comments
 (0)