Advertisement
betrayed

Linux - change user/usergroup/hostname/etc...

Mar 23rd, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. RENAMING : USER ACCOUNT / USER DIRECTORY / UID / HOSTNAME
  2.  
  3.  
  4. To avoid process-conflict when modifying a user, be sure that you're
  5. signed out of the account you're intending to modify.
  6.  
  7.  
  8.  
  9. ---[ step #1 ]-----------------------------------------------------
  10.  
  11. To create a new user:
  12. sudo adduser <username>
  13. *** enter a password when prompted ***
  14.  
  15. Make the account a super-user:
  16. sudo usermod -aG sudo <username>
  17.  
  18. ---[ step #2 ]-----------------------------------------------------
  19.  
  20. Now login to the dummy account! When you get in, open up a terminal.
  21.  
  22. Rename the user account you want to change:
  23. sudo usermod -l <new_username> <username>
  24.  
  25. ---[ step #3 ]-----------------------------------------------------
  26.  
  27. At this point, the user director (ex: /home/<username>) will also need
  28. to be renamed to match the new username you've selected, else there will
  29. be issues and all sorts of minor hang-ups.
  30.  
  31. You will want to copy the contents from the old user directory (including
  32. desktop contents, documents, etc) over to the new one. To do this:
  33. sudo usermod -d /home/<new_username> -m <old_username>
  34.  
  35. sudo ln -s /home/<new_username> /home/<old_username>
  36.  
  37. ---[ step #4 ]-----------------------------------------------------
  38.  
  39. You finally need to shift the user-group from the old username to the
  40. new one. You can do this by:
  41. sudo groupmod -n <new_username> <old_username>
  42.  
  43. ---[ step #5 ]-----------------------------------------------------
  44.  
  45. You may also want to set a new user-ID for the new username.
  46. Do this by doing:
  47. sudo usermod -u <uid> <new_username>
  48.  
  49. ---[ step #6 ]-----------------------------------------------------
  50.  
  51. If you want to change the hostname (computer name) of the machine.
  52.  
  53. Enter in this statement to see the current hostname:
  54. cat /etc/hostname
  55.  
  56. To change it:
  57. hostnamectl set-hostname <new_hostname>
  58.  
  59. You will also want to check the hosts file:
  60. cat /etc/hosts
  61.  
  62. Modify the line "127.0.1.1 <old_hostname>" and change that too:
  63. sudo mousepad /etc/hosts
  64.  
  65. *** change the hostname manually***
  66.  
  67. ---[ step #7 ]-----------------------------------------------------
  68.  
  69. Finally, you may choose to get rid of the dummy user you've used
  70. to make changes to the original user account:
  71.  
  72. sudo userdel <username>
  73.  
  74.  
  75.  
  76. References:
  77. https://www.youtube.com/watch?v=-nHmA75AcTM
  78. https://www.serverlab.ca/tutorials/linux/administration-linux/how-to-rename-linux-users-and-their-home-directory/
  79. https://www.youtube.com/watch?v=-nHmA75AcTM
  80.  
  81.  
  82. Note: Nautilus file explorer may not want to re-pin directories such as Documents, Music, and Videos
  83. on the left-hand side. To re-pin, manually navigate to the desired directory and hit CTRL + D to
  84. pin.
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement