How to clone a linux user?
Letβs take a look at how you can clone a linux user on a machine. The use case for this is when you want to create a new user with identical privileges as an existing user on the machine.
#!/bin/bash SRC=$1 DEST=$2 SRC_GROUPS=$(id -Gn ${SRC} | sed "s/ /,/g" | sed -r 's?\<'${SRC}'\>\b,?//g') SRC_SHELL=$(awk -F : -v name=${SRC} '(name == $1) { print $7 }' /etc/passwd) sudo useradd --groups ${SRC_GROUPS} --shell ${SRC_SHELL} --create-home ${DEST} sudo passwd ${DEST}
In order to use this script, assign executable permissions to this script and run the following command:
./[script_name] [user_to_clone] [cloned_user]
Test it out, and I hope you learned something new! π