Skip to content

A Passionate Techie

keep learning, keep growing

Enter your email address to follow this blog and receive notifications of new posts by email.

Recent learnings

  • Network monitoring tools September 5, 2021
  • Network Latencies September 5, 2021
  • Linux Network Stack September 5, 2021
  • Congestion control algorithms September 5, 2021
  • TCP performance features September 5, 2021

Recent Comments

gamejudilebaran.wordpress.com's avatargamejudilebaran.word… on Chef: Roles and Environme…
Unknown's avatarWARN: Waiting for se… on OSSEC start problem due to…
Arati Kulkarni's avatararatik711 on Ansible issues
Arati Kulkarni's avatararatik711 on Chef: Roles and Environme…
situs judi's avatarsitus judi on Chef: Roles and Environme…

Archives

  • September 2021
  • August 2021
  • March 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • February 2019
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • May 2017
  • April 2017
  • March 2017
  • January 2017
  • July 2015

Categories

  • aws
  • azure
  • centos
  • cloud
  • gcp
  • java
  • javascript
  • jenkins
  • linux
  • python
  • Uncategorized

Meta

  • Create account
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.com

Tag: adduser

unable to login to a virtual machine

If you want to add a user to a virtual machine without logging into it or change the password of root or any other user, you can use virt-customize.

The virt-customize command-line tool can be used to customize a virtual machine. For example, by installing packages and editing configuration files.
To use virt-customize, the guest virtual machine must be offline, so you must shut it down before running the commands. Note that virt-customize modifies the guest or disk image in place without making a copy of it. If you want to preserve the existing contents of the guest virtual machine, you must snapshot, copy or clone the disk first.

To install virt-customize, run one of the following commands:

sudo yum install libguestfs-tools-c
sudo apt-get install libguestfs-tools

Please follow the below-mentioned steps:

a. Add a new user:

virt-customize -a centos.img --run-command "adduser user1"

virt-customize -a centos.img --ssh-inject user1:string:<YOUR PUBLICKEY STRING HERE>

Now you can login with user1 and public-key
If you want passwordless sudo access execute the following:

virt-customize -a centos.img --run-command "echo 'user1 ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers.d/user1-sudo"

b. Change root password:

virt-customize -a centos.img --root-password password:mypass

You can login to the VM with root/mypass

c. Change password of non-root user:

virt-customize -a centos.img --password user1:password:mypass2

You can login to the VM with user1/mypass2

Rate this:

Share this:

  • Share on X (Opens in new window) X
  • Share on Facebook (Opens in new window) Facebook
Like Loading...
Posted on June 15, 2019June 15, 2019Categories UncategorizedTags adduser, cloud, guest, images, key, libguestfs, login, machine, private, public, qcow, qemu, ssh, tools, useradd, virsh, virt, virt-customize, virtual, vmLeave a comment on unable to login to a virtual machine
Blog at WordPress.com.
  • Subscribe Subscribed
    • A Passionate Techie
    • Join 108 other subscribers
    • Already have a WordPress.com account? Log in now.
  • Privacy
    • A Passionate Techie
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
%d
    Design a site like this with WordPress.com
    Get started