您的位置:首页 > 其它

修改Cloud image的密码的简单方法

2017-07-31 17:15 2471 查看
原文:

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 passwords
virt-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

(完)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cloud image