Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/bin/bash
- [ $UID = 0 ] || exit 1
- #if were here we are root, usually, but be root anyway
- echo "you are about to regex things, this is generally considered heavy handed and you are advised to take caution. ctrl-c now to quit without doing anything, otherwise press enter to continue."
- #pause the script
- line
- #ok, the real work
- read -p 'Enter Username: ' NEWNAME
- #rough test to ensure uniqueness
- grep $NEWNAME /etc/passwd
- [ $? = 1 ] && exit 1
- #back the files up to the fat partition so you can copy them over to a flash stick or something and put them back
- cp -t /boot /etc/passwd /etc/group /etc/shadow /etc/gshadow
- #do the change
- for i in {passwd, shadow, group, gshadow, sudoers}; do
- sed -i s/pi/$NEWNAME/g /etc/$i
- done
- #freshen the backups
- for i in {passwd, group, shadow, gshadow}; do cp /etc/$i /etc/$i-; done
- #I think were done, normally I do the changes by hand in nano and use regexes very sparingly
- #it is possible to back up these file first before doing this by copying them to another directory as root
- #so if your careful you can use this blunt instrument of a script
- #oh, and I added sudoers up their because otherwise your new username wouldn't have root access via the sudo command
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement