Сменить имя пользователя линукс

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.

Читайте также:  Linux show tcp ports

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:

Источник

Как изменить имя пользователя в Ubuntu, Debian, Deepin, Linux Mint, elementary OS или Fedora

В инструкциях объясняется, как изменить (переименовать) имя пользователя вместе с именем домашней папки пользователя, а также простой способ устранения потенциальных проблем с файлами конфигурации, которые все еще указывают на старое имя домашней папки. Также есть шаг для изменения полного имени (отображаемого имени), которое отображается на экране входа в систему и в других местах на рабочем столе.

Во всех приведенных ниже инструкциях или командах не забудьте заменить newusername его новым именем пользователя и oldusername старым именем пользователя.

1. Создайте временного пользователя и предоставьте ему привилегии sudo

Мы войдем в систему с временным пользователем, чтобы выполнить команды смены имени пользователя. Таким образом, не будет проблем при запуске их от того же пользователя, которого мы пытаемся переименовать (например, процессы, запущенные для этого пользователя и т. д.).

Добавьте нового временного пользователя ( tempuser ) и предоставьте ему привилегии sudo в Debian, Ubuntu, Deepin, elementary OS или Linux Mint (после ввода пароля вы можете продолжать нажимать, Enter чтобы пропустить ввод остальной информации):

sudo usermod -aG sudo tempuser

Добавьте новый tempuser и предоставьте ему привилегии sudo на Fedora:

sudo usermod -aG wheel tempuser

2. Войдите в систему как tempuser и измените (переименуйте) имя пользователя, домашнюю папку и группу

Выйдите из системы и на экране входа выберите tempuser и войдите под этим пользователем. Затем откройте терминал и выполните эти команды, чтобы изменить имя пользователя, домашнюю папку и группу с oldusername на newusername :

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

Если вы получили ошибку об использовании процесса для старого имени пользователя, убейте этот процесс ( kill PID ), но в большинстве случаев этого не должно происходить, поскольку мы вошли в систему, используя временное промежуточное имя пользователя для внесения этих изменений. Если это произойдет, другой обходной путь — это перезагрузить компьютер, а затем войти в tempuser напрямую, таким образом, нет никаких процессов, используемых старым именем пользователя.

Читайте также:  Можно ли обновить linux

3. Создайте символическую ссылку из /home/newusername в /home/oldusername

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

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

4. Измените отображаемое имя или полное имя (имя, фамилия)

В моем случае при попытке переименовать имя пользователя в Ubuntu 19.04 и Fedora 29 отображаемое имя (полное имя) осталось неизменным на экране входа в GDM3 и в меню пользователя. Это можно изменить, используя:

sudo chfn -f "firstname lastname" newusername

Заменить firstname и lastname с первым и последним именем, или что вы хотите, чтобы показать на экране входа и различных других местах по всей системе. firstname и lastname также может быть одним элементом, например, вашим новым именем пользователя.

Команда chfn доступна на Fedora в util-linux-user пакете, который не установлен по умолчанию. Вы можете установить его на Fedora, используя:

sudo dnf install util-linux-user

После установки этого пакета chfn команда должна работать на Fedora.

5. Войдите в систему с новым (переименованным) именем пользователя и удалите временного пользователя, созданного в шаге 1

Выйдите из системы, выберите новое, переименованное имя пользователя на экране входа в систему и перейдите к входу в систему. Теперь вы можете удалить временного пользователя, созданного в шаге 1 ( tempuser ), и его домашнюю папку:

Источник

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?

Читайте также:  Установка ldap astra linux

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:

    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 

Источник

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