Created
May 15, 2019 13:01
-
-
Save nsollazzo/a8f58c588704a609b0bafd0aebf802cc to your computer and use it in GitHub Desktop.
linux user clone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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