debian官網qcow2鏡像修改root賬號密碼,開啟ssh,修改源,語法高亮等


本文解決問題如下:

  1. 設置root賬號密碼
  2. 開啟root賬號ssh連接
  3. 開啟ssh語法高亮
  4. 解決vi編輯界面不允許復制問題

一、准備工作

1、下載官網qcow2鏡像文件

wget https://cloud.debian.org/images/cloud/OpenStack/10.2.0/debian-10.2.0-openstack-amd64.qcow2

鏡像文件信息

[debian-10.2-cloud]
name=Debian 10.2.0 (Buster) Cloud
osinfo=debian10
arch=x86_64
file=debian-10.2.0-openstack-amd64.qcow2
checksum[sha512]=296ad8345cb49e52464a0cb8bf4365eb0b9e4220c47ebdd73d134d51effc756d5554aee15027fffd038fef4ad5fa984c94208bce60572d58b2ab26f74bb2a5de
format=qcow2
size=566434304
revision=20191116
notes=Debian 10.2.0 (Buster).
 
 This is a Debian installation, suited for running as OpenStack guest.

2、使用openssl passwd -1 123456生成加密的密碼:-1表示使用MD5算法對密碼123456進行加密

[root@support01 ~]# openssl passwd -1 123456
$1$HDUWloxk$IZuLRX39Oa31T4YzCrCHL1

3、使用guestfish命令進入交互命令界面依次執行run、list-filesystems、mount等指令

guestfish --rw -a debian-10.2.0-openstack-amd64.qcow2
Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.

Type: 'help' for help on commands
      'man' to read the manual
      'quit' to quit the shell

><fs> run
><fs> list-filesystems
/dev/sda1: ext4
><fs> mount /dev/sda1 /
><fs>

 

二、修改root賬號密碼

編輯/etc/shadow

><fs> vi /etc/shadow
root:*:18216:0:99999:7:::
daemon:*:18216:0:99999:7:::
bin:*:18216:0:99999:7:::
sys:*:18216:0:99999:7:::
sync:*:18216:0:99999:7:::
games:*:18216:0:99999:7:::
man:*:18216:0:99999:7:::
lp:*:18216:0:99999:7:::
mail:*:18216:0:99999:7:::
news:*:18216:0:99999:7:::
uucp:*:18216:0:99999:7:::
proxy:*:18216:0:99999:7:::
www-data:*:18216:0:99999:7:::
backup:*:18216:0:99999:7:::
list:*:18216:0:99999:7:::
irc:*:18216:0:99999:7:::
gnats:*:18216:0:99999:7:::
nobody:*:18216:0:99999:7:::
_apt:*:18216:0:99999:7:::
systemd-timesync:*:18216:0:99999:7:::
systemd-network:*:18216:0:99999:7:::
systemd-resolve:*:18216:0:99999:7:::
messagebus:*:18216:0:99999:7:::
unscd:*:18216:0:99999:7:::
ntp:*:18216:0:99999:7:::
sshd:*:18216:0:99999:7:::

將root:后面的第一個*替換為第二步加密之后的密碼

替換后第一行為/etc/shadow第一行為

root:$1$HDUWloxk$IZuLRX39Oa31T4YzCrCHL1:18216:0:99999:7:::

 

三、開啟root賬號ssh遠程登錄

編輯/etc/ssh/sshd_config,在vi中:set number開啟行號

><fs> vi /etc/ssh/sshd_config

第32行

#PermitRootLogin prohibit-password

釋放掉注釋,並修改值為yes,調整完之后第32行為

PermitRootLogin yes

第56行

#PasswordAuthentication yes

釋放掉注釋,調整完之后第56行為

PasswordAuthentication yes

 

四、修改apt源,(qcow2注冊到OpenStack之后啟動虛擬機源還是默認的,目前原因未知,可待虛擬機啟動后執行下列修改)

編輯/etc/apt/sources.list,將替換為以下內容

deb http://mirrors.163.com/debian/ buster main contrib non-free
# deb-src http://mirrors.163.com/debian/ buster main contrib non-free
deb http://mirrors.163.com/debian/ buster-updates main contrib non-free
# deb-src http://mirrors.163.com/debian/ buster-updates main contrib non-free
deb http://mirrors.163.com/debian/ buster-backports main contrib non-free
# deb-src http://mirrors.163.com/debian/ buster-backports main contrib non-free
deb http://mirrors.163.com/debian-security buster/updates main contrib non-free
# deb-src http://mirrors.163.com/debian-security buster/updates main contrib non-free

 

五、開啟ssh語法高亮以及內置命令別名

編輯/root/.bashrc,1、3、4、8、15行為說明注釋,除此之外釋放所有注釋

><fs> vi /root/.bashrc

編輯之前內容為:

# ~/.bashrc: executed by bash(1) for non-login shells.

# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022

# You may uncomment the following lines if you want `ls' to be colorized:
# export LS_OPTIONS='--color=auto'
# eval "`dircolors`"
# alias ls='ls $LS_OPTIONS'
# alias ll='ls $LS_OPTIONS -l'
# alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'

編輯之后內容為:

# ~/.bashrc: executed by bash(1) for non-login shells.

# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
umask 022

# You may uncomment the following lines if you want `ls' to be colorized:
export LS_OPTIONS='--color=auto'
eval "`dircolors`"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

六、允許在vi窗口中復制文本

><fs> vi /usr/share/vim/vim81/defaults.vim

78、79、80三行內容為:

if has('mouse')
  set mouse=a
endif

在“=”前面添加一個“-”,編輯后內容為:

if has('mouse')
  set mouse-=a
endif

 

最后執行quit命令退出guestfish,將qcow2鏡像文件注冊到openstack,投遞虛擬機實例即可

 

參考鏈接:

https://docs.openstack.org/image-guide/modify-images.html#guestfish

https://blog.51cto.com/superzhangqiang/1705678

https://blog.csdn.net/weixin_42551369/article/details/88946622

http://www.chenshake.com/openstack-mirror-and-password/ 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM