Сменить имя пользователя linux

How do I change my username?

Some time ago, when I installed Ubuntu, I chose a rather stupid username for my account that I do not want to use anymore. How do I change this (including the name of my home directory, and the name in the terminal) without losing settings for applications?
How do I keep permissions and my keys for various authentification (e.g. email, SSH, GPG and more)?
What settings could possibly get lost if I changed my username?

Why can’t we navigate to /usr/share/applications/users.desktop >> Click on the user for which the name has to be changed. >> Click on Change User name >> Change the name >> Click on Ok. I think, this would be the easiest way to change the username, wouldn’t it?

8 Answers 8

Unix-like operating systems decouple the user name from the user identity, so you may safely change the name without affecting the ID. All permissions, files, etc are tied to your identity (uid), not your username.

To manage every aspect of the user database, you use the usermod tool.

To change username and user’s groupname (it is probably best to do this without being logged in):

sudo usermod -l newUsername oldUsername sudo groupmod -n newUsername oldUsername 

This however, doesn’t rename the home folder.

sudo usermod -d /home/newHomeDir -m newUsername 

after you changed the username.

For instance, you could logout, drop to a console ( Ctrl + Alt + F1 ), and sudo su — to become true root (as opposed to sudo -s , where $HOME is still /home/yourname.) Maybe you also have to kill some still running processes from this user first. To do so, enter ps -u username , look for the matching PID and kill them by kill PID-number .

Update: as arrange mentioned, some files may reference your old home directory. You can either keep a symlink for backward compatibility, e g ln -s /home/newname /home/oldname or you can change the file contents with sed -i.bak ‘s/*oldname*/*newname*/g’ *list of files* It creates a backup for each file with a .bak extension.

Some additional information for not so experienced users like me:
As I only have ONE user account (administrator), it would not let me change the username («you are already logged in» was the response in TTY1 ( Ctrl + Alt + F1 ). To get around this:

Читайте также:  Посмотреть права папки linux

    Login with your old credentials and add a new user, e.g. «temporary» in TTY1:

set the password. 2. Allow the temporary user to run sudo by adding the user to sudo group:

 sudo adduser temporary sudo 
  1. Log out with the command exit .
  2. Return to tty1: Login with the ‘temporary’ user account and password. Change your username and folder as mentioned above. exit (until you get the login prompt)
  3. Go back to TTY7 ( Ctrl + Alt + F7 ) to login on the GUI/normal desktop screen and see if this works.
  4. Delete temporary user and folder:
sudo deluser temporary sudo rm -r /home/temporary 

Источник

How To Change Username On Ubuntu, Debian, Linux Mint Or Fedora

This is a step by step guide on how to change your username on Debian, Ubuntu, Linux Mint (and other Linux distributions based on Debian/Ubuntu), and Fedora.

The instructions explain how to change (rename) the username along with the user’s home folder name, as well as a simple work-around for potential issues with configuration files that still point to the old home folder name. There’s also a step for changing the full name (display name), which is shown on the login screen and other places throughout the desktop.

Throughout all the instructions / commands below, remember to replace newusername with the new username, and oldusername with the . old username.

1. Create a temporary user and give it sudo privileges.

We’ll login with the temporary user to perform the username change commands. This way there won’t be any issues running them from the same user we’re trying to rename (e.g. processes running for that user, etc.).

Add a new temporary user ( tempuser ) and give it sudo privileges on Debian, Ubuntu or Linux Mint (after entering a password you can keep pressing Enter to skip entering the rest of information):

sudo adduser tempuser sudo usermod -aG sudo tempuser

Add a new tempuser and give it sudo privileges on Fedora:

sudo adduser tempuser sudo passwd tempuser sudo usermod -aG wheel tempuser

2. Login with tempuser and change (rename) the username, home folder and group.

Logout, and on the login screen select tempuser and login with that user. Next, open a terminal and run these command to change your username, home folder, and group from oldusername to newusername :

sudo usermod -l newusername -d /home/newusername -m oldusername sudo groupmod -n newusername oldusername

If you get an error about a process being in use for the old username, kill that process ( kill PID ), but that shouldn’t happen in most cases since we’re logged in using a temporary, intermediate username to make these changes. If it does happen, another workaround is to reboot and then login straight with tempuser , that way there aren’t any processes used by the old username.

Читайте также:  Pip install requests linux

3. Create a symbolic link from /home/newusername to /home/oldusername .

Some applications will show errors when changing the username, because in some cases there are configuration files that point to the old username’s home folder. A solution for this is to create a symbolic link from the new home folder to the old home folder:

sudo ln -s /home/newusername /home/oldusername

4. Change the display name / full name (firstname lastname).

In my case, trying to rename a username on Ubuntu 19.04 and Fedora 29, the display name (full name) remained unchanged on the GDM3 login screen and on the user menu. This can be changed though, using:

sudo chfn -f "firstname lastname" newusername

Replace firstname and lastname with your first and last name, or whatever you want to show up on the login screen and various other places throughout the system. firstname and lastname can also be one item, e.g. your new username.

The chfn command is available on Fedora in the util-linux-user package, which is not installed by default. You can install it on Fedora using:

sudo dnf install util-linux-user

After installing this package, the chfn command should work on Fedora.

5. Login using the new (renamed) username, and delete the temporary user created on step 1.

Logout and select the new, renamed username from the login screen, and proceed to login. You can now delete the temporary user created in step 1 ( tempuser ) and its home folder:

Источник

🐧 Как правильно изменить имя пользователя на Linux

В этом кратком руководстве объясняется, как правильно изменить имя пользователя в операционной системе Linux.

Э то руководство также описывает, как изменить имя хоста, группу пользователей, домашний каталог, а также владельца и группу этого каталога на нового пользователя вместе со всеми файлами.

Читайте также:  Fedora linux install package

Если вы когда-нибудь искали правильный способ изменить имя пользователя в Linux, не нарушая существующие файлы конфигурации, далее объясняется, как это сделать!

Предупреждение:

Я бы не рекомендовал это в производственной среде.

Всегда лучше просто создать нового пользователя, а не переименовывать существующего.

Потому что переименование имени пользователя вызовет так много проблем, если на домашний каталог старого пользователя ссылаются некоторые другие файлы конфигурации.

Вы можете в конечном итоге изменить файлы конфигурации, используемые таким количеством служб. Также не делайте этого, если ваш каталог $HOME зашифрован!

Поэтому я рекомендую вам создать нового пользователя и перенести данные старого пользователя на нового.

Если это недавно установленная система или просто тестовая система, вы можете изменить имя пользователя, как описано ниже.

Правильный способ изменить имя пользователя на Linux

Изменить имя хоста в Fedora и других дистрибутивах Linux очень просто!

Войдите в систему как пользователь sudo или root.

Я вошел в систему как пользователь root.

Измените текущее имя хоста с помощью команды hostnamectl, как показано ниже:

# hostnamectl set-hostname fedora33

Вы также можете проверить это с помощью команды hostname:

В этом руководстве я использовал одно и то же имя для пользователя и группы.

Вы можете использовать другое имя, если хотите.

А затем изменил имя пользователя с помощью команды usermod, как показано ниже:

# usermod -d /home/itisgood -m -g itisgood -l itisgood vagrant

Давайте разберем приведенную выше команду и посмотрим, что делает каждая опция.

  • usermod: команда для изменения учетной записи пользователя в Unix-подобных системах.
  • -d /home/itisgood: создать новый каталог $HOME для пользователя.
  • -m: переместить содержимое каталога $HOME старого пользователя в новое место.
  • -g itisgood: добавить нового пользователя в группу под названием «itisgood».
  • -l itisgood vagrant: изменить имя пользователя с «vagrant» на «itisgood». т.е. “vagrant” – это старое имя пользователя, а “itisgood” – это новый пользователь.

Вышеупомянутая команда изменяет имя пользователя, группу пользователей, каталог $HOME, владельца и группу этого каталога на нового пользователя, а также все файлы и каталоги пользователя.

Наконец, назначьте привилегии sudo новому пользователю с помощью команды:

# usermod -aG wheel itisgood

Если вы используете системы на основе Debian, такие как Ubuntu, вы можете предоставить пользователю разрешения sudo с помощью этой команды:

$ sudo usermod -aG sudo itisgood

Убедитесь, что имя хоста, имя пользователя и каталоги $HOME изменены!

Источник

Оцените статью
Adblock
detector