Always Geeky

Knowledge base for various geeky topics
 

+menu-

Copying Linux encrypted shadow password

If you need to copy a Linux user account from one system to another and need to presever the password without knowing it, you can use this process.

First, create the user:


sudo useradd bob

Set group membership as required, such as appending the wheel group:


sudo usermod -a -G wheel bob

Grab the hashed password from the existing system – you are after everything between the first and second colon (:), which should start with a $6$.

sudo grep bob /etc/shadow
$6$N9ZbvcsuQTabj4NN8AS3G37.SDEtFNh588qydwE3kefAxraCwH2P3ZSBQBkhsyjzyhsNuZjr2DC/qzNHSQBPTnz.PNRvfhc

Use sudo vipw -s to add the above encrypted string to the new shadow file. vipw uses locks to avoid concurrencies issues with this file, so use this instead of manually editing the shadow file.

Done!

This entry was posted in Linux and tagged , . Bookmark the permalink.

 

Leave a Reply