อาจได้ยิน Amazon Linux 2 OS ของ AWS พัฒนาโดย Amazon ฟรี และมี VM appliances สำหรับทดสอบ ตามที่แสดงในบทความเก่า
Snag ที่เจอระหว่างทดสอบ: login ปกติ SSH เข้า EC2 instances แต่ offline VM ใช้ไร? หา root/ec2-user combo online ไม่เจอ single mode change password ไม่ได้ จึงมีคู่มือนี้ แสดงวิธี manual change login credentials Amazon Linux 2 VM เริ่มทดสอบได้ ตามมา
Login Prompt
Download image Boot Login What now?
(ภาพประกอบ login prompt)
Single Mode
Long-time Linux users จะจำ trick: force single mode remount root writable change password reboot ทำมาเยอะ Alas no longer possible
ลอง append init=/bin/bash boot options boot menu kernel panic ไม่แน่ใจ kernel, Amazon Linux 用 systemd หรืออื่นๆ old proven method ไม่ช่วย
อ่านออนไลน์ นอกจาก million bin-bash entries yield nothing พบ detailed article change password RHEL 7 mention philosophical concept change transitioning RHEL 6 to 7 part of RHCSA exam I mean what? Where simplicity gone?
เพิ่ม rd.break kernel line might help Amazon Linux 2 based on RHEL ลองทำ แต่ nothing Amazon Linux blithely booted normally ไม่ได้ผล
(ภาพประกอบ)
Amazon มี passage สั้น vague ว่าสร้าง cloud-init configuration ISO refer virtualization platform documentation ไม่ helpful
Mount VDI Manually
พูดถึงในอดีต showed mount VM disks/partitions loopback devices edit filesystem contents used partx clone KVM machines ทำ same thing here show another way mount/present VM image filesystems
ต้องการ qemu-nbd tool similar trick available qemu-kvm package most distros install แล้วใช้ tool หาก fail อาจต้อง manually load nbd (network block device) module คำสั่ง sequence (sudo/root):
install qemu-kvm modprobe nbd qemu-nbd -c /dev/nbd0
Locate Amazon Linux 2 vdi image map ในคำสั่ง ไม่จำเป็นต้อง /dev/nbd0 ใช้ number ไหนก็ได้ แต่ sequential easier/cleaner
Once block device mapped partitions under /dev/nbd0p* numbers match actual disk layout p1, p2, etc คล้าย partx mount partition ที่ต้องการ:
mount /dev/nbd0pX /mountpoint
Done command ได้ contents Amazon Linux 2 vdi filesystem (partition) exposed under mountpoint (e.g. /mnt) manipulate ได้
Edit /etc/shadow File
เปลี่ยน password: บน native Linux (running VM) สร้าง user ใหม่ เรียกอะไรก็ได้ amazon สร้าง password เปิด /etc/shadow password encrypted long hash ระหว่าง two colon delimiters นี่คือสิ่งที่ต้องการ:
amazon:$123456$dedoimedo:11111:0:99999:6:::
Navigate Amazon Linux 2 filesystem mountpoint (/mnt) เปิด shadow file text editor:
/mnt/etc/shadow
Default user = ec2-user (ตอนนี้รู้แล้ว) มี hash password ไม่รู้คืออะไรไม่สำคัญ Replace hash ด้วย local amazon user Save file unmount vdi
(ภาพประกอบ shadow file edit)
Reboot, Login, Work, Enjoy
Start VM อีกครั้ง Login prompt identify correctly username/password ที่ planted logged in เริ่มงาน VM ทำกับ Amazon Linux แต่ trick นี้ applies to ALL Linux distributions/filesystems หากไม่ run system maintenance normally ใช้ trick นี้ bypass limitation make necessary changes filesystem useful for VMs ทำกับ KVM และ VirtualBox
(ภาพประกอบ login success)
สรุป (Conclusion)
หาก keen test Amazon Linux 2 แต่ hit login credentials snag ไม่อยากสร้าง ISO images หรือ figure out full proper way EC2 stuff ใช้ partx หรือ qemu-nbd mount virtual hard disk manually edit shadow file guaranteed workaround หาก boot single/rescue mode ไม่ cut it
Amazon Linux 2 fun OS interesting features shame miss them technical/bureaucratic bungle initial login/password no reason no default set like any distro generic changes Linux infrastructure init=/bin/bash ไม่ช่วย หวังว่า article gives technical know-how adventurous spur start journey distro-agnostic any VM appliance any filesystem make necessary changes testing Have fun exploring.
Cheers.