修改Cloud image的密碼的簡單方法

原文:

https://scottlinux.com/2017/05/08/set-password-or-ssh-key-for-centos-cloud-images/


CentOS爲各種不同的雲環境提供cloud images,比如OpenStack,RHV,AZure,或KVM. 一般來說,是通過cloud-init工具來修改用戶密碼或SSH keys. 但是那似乎不太方便。 下面是一種方便的方法。

官方的CentOS的cloud image的下載地址是:

http://cloud.centos.org/centos/7/images/


第一步,安裝軟件libguestfs-tools


sudo yum install libguestfs-tools
或
sudo apt install libguestfs-tools
或
sudo dnf install libguestfs-tools


第二步,設定一個固定密碼



sudo virt-customize -a CentOS-7-x86_64-GenericCloud-1703.qcow2 --root-password password:passw0rd


結束。


這一步也可以設一個隨機密碼:


sudo virt-customize -a CentOS-7-x86_64-GenericCloud-1703.qcow2 --root-password random[   0.0] Examining the guest ...[  11.2] Setting a random seed[  11.2] Setting passwordsvirt-customize: Setting random password of root to 132Tfe6cfCCr8Pv8[  12.2] Finishing off


這一步還可以是這樣:安裝或刪除package,甚至同時設置自己的SSH key



sudo virt-customize -a CentOS-7-x86_64-GenericCloud-1703.qcow2 --install epel-release --ssh-inject centos:string:"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKCqX6EZIrGHoGaMII4QAqr0QC72t+Kg/c5ZIRNTMb6Q+BwzejQgjhBTXeyPnp0rfE9XI4pTxkZqAUOGSK9Bfqg= smiller@bruckner"



[譯者注]

以上的文章完結了。但在實際使用過程中,往往我們還希望能夠ssh到這個cloud image的instance上。此時發現cloud image默認是不允許用root以及密碼進行登錄的。那麼解決辦法就是:

1. 編輯 /etc/ssh/sshd_config 文件,將其中的下面2句話釋放出來:


PermitRootLogin yes
PasswordAuthentication yes

2. 重啓sshd

(完)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章