Skip to content

Instantly share code, notes, and snippets.

@rpavlik
Last active March 10, 2024 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpavlik/ce24433e0604ef52f334c0de25936535 to your computer and use it in GitHub Desktop.
Save rpavlik/ce24433e0604ef52f334c0de25936535 to your computer and use it in GitHub Desktop.
Linux name change
# from https://askubuntu.com/a/1363020
wsl -l -v
wsl --terminate Debian # <distro> from the previous command
wsl -u root -d Debian # "-d <distro>" is only needed for non-default instances
# Now from in WSL
usermod -l rylie ryan
# Optionally change the home directory name to match
usermod -d /home/rylie -m rylie
# Optionally change the group name to match
groupmod -n rylie ryan
#!/bin/sh
# see https://www.golinuxcloud.com/how-to-change-username-on-linux/#Method-2_Change_username_on_Linux_without_usermod_command
# as root
# rename user and group
sed -i 's/^ryan/rylie/' /etc/passwd
sed -i 's/^ryan/rylie/' /etc/shadow
sed -i 's/ryan/rylie/' /etc/groups
# Move home dir
mv /home/ryan /home/rylie
# compatibility symlink
ln -s /home/rylie /home/ryan
# Update home dir in user database
sed -i 's:/home/ryan:/home/rylie:' /etc/passwd
wsl --shutdown
# Fix default user for wsl
# https://learn.microsoft.com/en-us/windows/wsl/basic-commands#change-the-default-user-for-a-distribution
debian config --default-user rylie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment