vlambda博客
学习文章列表

修改openstack Centos镜像的默认用户的密码

Ubuntu官方提供的OpenStack镜像是用Key来登录的,太麻烦,可以改成用密码来登录。

 

修改image的工具叫:guestfish

 

1、安装修改的工具

[root@server-3images]# yum install libguestfs-tools -y

Failed to set locale, defaulting to C.UTF-8
Repository extras is listed more than once in theconfiguration
Last metadata expiration check: 1:13:27 ago on SunApr 18 13:13:08 2021.
Dependencies resolved.
================================================================================================================================================================================================================
 Package                                           Architecture                        Version                                                                 Repository                              Size
================================================================================================================================================================================================================
Installing:
 libguestfs-tools                                   noarch                              1:1.40.2-25.module_el8.3.0+555+a55c8938                                 AppStream                               28 k
Installing dependencies:

 libguestfs-tools                                   noarch                              1:1.40.2-25.module_el8.3.0+555+a55c8938                                 AppStream                               28 k

Installing dependencies:

 hexedit                                           x86_64                              1.2.13-12.el8                                                           AppStream                               46 k

 libguestfs-tools-c                                 x86_64                              1:1.40.2-25.module_el8.3.0+555+a55c8938                                 AppStream                              5.6 M

 perl-Class-Inspector                               noarch                               1.32-2.el8                                                              AppStream                               37 k

 Verifying        :perl-libintl-perl-1.29-2.el8.x86_64                                                                                                                                                 10/10

Installed products updated.

 

Installed:

 hexedit-1.2.13-12.el8.x86_64                                       libguestfs-tools-1:1.40.2-25.module_el8.3.0+555+a55c8938.noarch     libguestfs-tools-c-1:1.40.2-25.module_el8.3.0+555+a55c8938.x86_64   

 libguestfs-xfs-1:1.40.2-25.module_el8.3.0+555+a55c8938.x86_64      perl-Class-Inspector-1.32-2.el8.noarch                              perl-File-ShareDir-1.104-3.el8.noarch                               

 perl-Sys-Guestfs-1:1.40.2-25.module_el8.3.0+555+a55c8938.x86_64    perl-Sys-Virt-6.0.0-1.module_el8.3.0+555+a55c8938.x86_64            perl-hivex-1.3.18-20.module_el8.3.0+555+a55c8938.x86_64             

 perl-libintl-perl-1.29-2.el8.x86_64                               

 

Complete!

 

2、打开下载的镜像

##ubuntu 的官方镜像站: http://cloud-images.ubuntu.com/
##centos 的官方镜像站: http://cloud.centos.org/

##[root@server-3images]# wget http://cloud-images.ubuntu.com/releases/groovy/release-20210209/ubuntu-20.10-server-cloudimg-arm64.img

 

[root@server-3images]# pwd

/var/lib/libvirt/images

[root@server-3images]# ls

CentOS-7-x86_64-GenericCloud-1607.qcow2  ubuntu-20.10-server-cloudimg-arm64.img

[root@server-3images]# guestfish --rw -a ubuntu-20.10-server-cloudimg-arm64.img

 

Welcome to guestfish, the guest filesystem shell for

editing virtual machine filesystems and disk images.

 

Type: ‘help’ for help on commands

      ‘man’ toread the manual

      ‘quit’ toquit the shell

 

><fs> run                                  #先运行这个镜像

 100%[#################################################################################################################################################################################################]--:--

><fs> list-filesystems                           #列出所有的文件系统

/dev/sda1: ext4 

/dev/sda15: vfat

><fs> mount /dev/sda1 /              #挂载到根目录

><fs> vi /etc/cloud/cloud.cfg

编辑文件/etc/cloud/cloud.cfg,因为我们要修改默认用户root的密码并且开启rootssh登陆,很简单加入下面的内容就行了,上面两个是修改。