ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
# 更換CoreOS不安全的ssh key `coreos_production_vmware_insecure`的登入方式使用公開的ssh key,任何一個下載同一份`zip`檔案的人,都可以利用相同的ssh key登入,十分危險。本小節說明如何把這不安全的ssh key刪除掉,並換成使用者自己安全的ssh key。使用Ubuntu Linux作為ssh的客戶端示範。 ### 換成安全的ssh key 1. 先確定你擁有自己的ssh key,輸入`ls ~/.ssh -al`,要有`id_rsa.pub`這個檔案。 ![](https://box.kancloud.cn/2015-08-09_55c7597d74cc2.png) 1. 將自己的ssh key加入CoreOS主機中安全ssh key的清單中。CoreOS中有一個更新ssh key的專門script檔`update-ssh-keys`,用來把自己安全的ssh key更新到CoreOS的主機ssh key允許清單中。假如CoreOS的 IP是192.168.1.109,則輸入:`cat ~/.ssh/id_rsa.pub | ssh core@192.168.1.109 -i insecure_ssh_key update-ssh-keys -a safeuser` 1. 完成之後,直接進入CoreOS,不需要舊的`insecure_ssh_key`了。輸入:`ssh core@192.168.1.109`。 ![](https://box.kancloud.cn/2015-08-09_55c7597d807be.png) 1. 進入CoreOS之後查看目前的key,包括了舊有不安全的,和剛才加入安全的Key。 ![](https://box.kancloud.cn/2015-08-09_55c7597d92942.png) 1. 把舊的不安全的key移除,輸入`update-ssh-keys -D coreos-cloudinit`即可。 ![](https://box.kancloud.cn/2015-08-09_55c7597daaaab.png) 1. 此時用原來舊的KEY已經進不去了。 ![](https://box.kancloud.cn/2015-08-09_55c7597dbd0a2.png) 1. 如果你的CoreOS在重新開機後IP變了,你可能會進不去了,會出現如下的畫面 ~~~ joshhu@ubuntu:~$ ssh core@192.168.1.109 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that a host key has just been changed. The fingerprint for the ED25519 key sent by the remote host is 5e:a8:6e:7f:36:21:8c:1d:24:c7:37:0d:df:96:44:ae. Please contact your system administrator. Add correct host key in /home/joshhu/.ssh/known_hosts to get rid of this message. Offending ECDSA key in /home/joshhu/.ssh/known_hosts:1 remove with: ssh-keygen -f "/home/joshhu/.ssh/known_hosts" -R 192.168.1.109 ED25519 host key for 192.168.1.109 has changed and you have requested strict checking. Host key verification failed. ~~~ 此時只要輸入`ssh-keygen -f "/home/joshhu/.ssh/known_hosts" -R 192.168.1.109`來更新ssh key,就可以正常登入了。