Skip to content

Instantly share code, notes, and snippets.

@nsollazzo
Created May 15, 2019 13:01
Show Gist options
  • Save nsollazzo/a8f58c588704a609b0bafd0aebf802cc to your computer and use it in GitHub Desktop.
Save nsollazzo/a8f58c588704a609b0bafd0aebf802cc to your computer and use it in GitHub Desktop.
linux user clone
#!/bin/bash
SRC=$1
DEST=$2
SRC_GROUPS=$(id -Gn ${SRC} | sed "s/${SRC} //g" | sed "s/ ${SRC}//g" | sed "s/ /,/g")
SRC_SHELL=$(awk -F : -v name=${SRC} '(name == $1) { print $7 }' /etc/passwd)
useradd --groups ${SRC_GROUPS} --shell ${SRC_SHELL} --create-home ${DEST}
passwd ${DEST}
# make it executable: chmod +x clone-user.sh
# usage: ./clone-user src_user_name new_user_name
# source: https://unix.stackexchange.com/questions/204970/clone-linux-user-copy-user-based-on-another-one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment