qcow2镜像自定义设置
本文解决问题如下:
- 设置root账号密码
- 开启root账号ssh连接
- 开启ssh语法高亮
- 解决vi编辑界面不允许复制问题
一、准备工作
1、下载官网qcow2镜像文件
https://cloud.centos.org/centos/7/images/
2、使用openssl passwd -1 123456生成加密的密码:-1表示使用MD5算法对密码123456进行加密
123123是:$1$8/FWM9Ne$mlcU5.J1aGxHdZ.jSmSV00
[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:::
将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
五、开启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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫