Linux下手動修改忘記密碼的kvm image__Linux

來源:互聯網
上載者:User
聲明

此文檔只做學習交流使用,請勿用作其他商業用途
author : 朝陽_tony
E-mail : linzhaolover@163.com
Create Date: 2016-10-18 13:10:37
Last Change: 2016-10-18 16:10:44
轉載請註明出處:http://blog.csdn.net/linzhaolover

現在虛擬機器kvm的使用很流行,為了更多的差異化環境,每個人可能擁有很多的kvm,這數量一多難免會有image的密碼會忘記,相信很多人會採用kernel single user 單一使用者模式進入系統修改秘密,但是,自從rhel7和ubuntu14.04以後,都加了認證,進入單使用者後,還要求輸入密碼,這的確增加了安全性。下面就簡單介紹一下通過libguestfs-tools這個工具直接修改image中的檔案,無需啟動kvm。 查看kvm list

# virsh list --all Id    Name                           State---------------------------------------------------- -     rhel7.0                        shut off -     rhel7.0-cloud                  shut off -     ub12-clear                     shut off -     ub14.04-clear                  shut off -     ub14.04-clear-clone            shut off -     ubuntu14.04                    shut off

rhel7.0 這個就是我需要修改密碼的kvm 安裝libguestfs-tools

sudo yum install libguestfs-tools      # Fedora/RHEL/CentOSsudo apt-get install libguestfs-tools  # Debian/Ubuntu

安裝完成後會增加很多virt命令,這次我們主要使用virt-edit 產生新的密碼串

# openssl passwd -1 -salt 'hello' '123456'$1$hello$ZwmhCpcG.I1XIfVjdarKc1

openssl是一個加密工具,-1 是指普通加密,hello為key , 123456 才是密碼,下面就是是產生的密碼串,這樣我們只要將這些進行對應的替換酒可以了
linux系統的加密密碼通常儲存在/etc/shadow 檔案中

root:$1$bTPRDWwf$LpjUZmGTHw.hYFccl0/lK.:16804:0:99999:7:::                                                                                    bin:*:15937:0:99999:7:::daemon:*:15937:0:99999:7:::adm:*:15937:0:99999:7:::lp:*:15937:0:99999:7:::sync:*:15937:0:99999:7:::shutdown:*:15937:0:99999:7:::
修改系統root賬戶密碼
virt-edit -d rhel7.0 /etc/shadow

視kvm image大小情況而定,一般一兩分鐘就可以開啟,我們只要替換root中的對應部分酒可以

root:$1$bTPRDWwf$LpjUZmGTHw.hYFccl0/lK.:16804:0:99999:7:::更換為root:$1$hello$ZwmhCpcG.I1XIfVjdarKc1:16541:0:99999:7:::

儲存退出,啟動kvm,就可以用最新的密碼進入了,當前最新密碼是123456

http://libguestfs.org/virt-edit.1.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.