Linux user home folder

👥 Как создать домашний каталог для существующего пользователя Linux

По умолчанию, когда вы создаете пользователя в Linux, домашний каталог создается в каталоге /home.

Возможно вы заметили, что в производных дистрибутивах Ubuntu и Debian команда useradd по умолчанию не будет создавать домашний каталог.

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

В этом руководстве я покажу вам, как создать домашний каталог по умолчанию для существующего пользователя в системах Linux.

Создание домашнего каталога по умолчанию для существующего пользователя

В примере я использую Ubuntu 20.04 и собираюсь создать пользователя с именем ‘bob’ с помощью команды useradd:

Если я попытаюсь войти в систему от этого пользователя, используя su -, система показывает logging in with Home=/

Это означает, что домашний каталог пользователя не создан.

В Linux домашним каталогом пользователя по умолчанию является /home.

Чтобы создать домашний каталог по умолчанию, используйте команду mkhomedir_helper.

Обязательно запустите команду mkhomedir_helper от имени пользователя root или пользователя с доступом sudo.

В графической среде (например, GNOME или XFCE), если вам не хватает подкаталогов в домашнем каталоге, пользователь должен выйти из системы и войти обратно.

При первом входе пользователя в систему все подкаталоги, такие как папки Pictures, Documents, Videos, и Downloads , могут быть созданы в домашнем каталоге.

Другой метод – удалить пользователя и создать нового пользователя с помощью параметра -m или –create-home.

Следующая команда создает домашнюю папку (-m) и задаст указанный домашний каталог (-d) в качестве значения для входа нового пользователя:

Заключение

В заключение, если вы являетесь поклонником Ubuntu, вы должны теперь использовать команду adduser.

Если у вас уже есть пользователь, теперь вы сможете добавить каталог по умолчанию.

Источник

How to Create Home Directory for Existing User in Linux

By default when you create a user in Linux, users default home directory is created under /home. If you noticed on Ubuntu and Debian derivated distribution useradd command won’t create a home directory by default.

Let’s think of s situation where you have already created a user but the home directory is missing. In this tutorial, I will show you how to create a default home directory for an existing user in Linux.

Create default home directory for existing user

Here I am using Ubuntu 20.04 and going to create a user named ‘ bob’ using useradd command:

Useradd command has added an entry home directory in /etc/passwd file

If I try to login as the user using su — , it shows that it’s logging in with Home=/ . This means the user home directory is not created.

Читайте также:  Windows 7pe мини версия что это

In Linux, a user’s default home directory is /home. To create a default home directory use mkhomedir_helper command.

Make sure to run mkhomedir_helper command as root or user with sudo access.

The previous command creates a home directory named «/home/bob» and user settings files.

For a graphical environment (such as GNOME or XFCE ), if you are missing subdirectories in the home directory, the user needs to log out and log in back.

When the user login the first time all subdirectories such as Pictures, Documents, Videos, and Downloads folders can be created in the home directory.

Another method is to delete the user and create a new user using -m or —create-home option.

The following command creates a home folder (-m) and set the specified home directory (-d) as the value for the new user’s login:

Conclusion

To conclude, If you are a Ubuntu fan you should be now using adduser command, it’s recommended by Debian. If you have an existing user, now you should be able to add default directory.

Thanks for reading and please drop your suggestions on the below comment section.

Источник

Linux directory structure: /home and /root folders

This is our 6 th post on understanding first level directories in /. Knowing these folders in detail or at least what each is meant for will help you understand Linux/Unix in whole. we already covered below directories, please have a look at those to understand them. In this post we will see two more directories ie /home and /root directory. These directories are meant for similar purpose. The /root is meant for just root user and /home is for all the remaining users.

A brief intro to /home directory in Linux/Unix

The /home directory is a place where by default all user home directories are created.

OK, what are user home directories for?

These directories are a kind of personal place(Working space) for all the users other than root. There will be a separate folder for each user in /home directory. For example if you have a user called ‘Tom’, then his default home directory is /home/tom. We can change this default folder when creating user in Linux. Our Tom user can do what ever he wants in /home/tom folder where he have full rights on the files he created and owned in that folder.

The properties of /home folder?

1) A separate sub folder ie /home/ is present for each user.
2) Only user who owns this sub folder can access its content other than root user. So, tom user can not access Barbi user home directory content which is located at /home/barbi.
3) All his terminal properties, command history file, application setting files(

/.ssh) etc everything is located in this folder.
4) System admins when try to implement quota for users they will implement it on /home directory. This /home directory should be mounted on a separate partition.

Each user home directory is important and frequently used directory for that user, we have alias name for it. This alias is set to

Читайте также:  Kms активатор windows 10 руторг

so that when ever user wants to navigate to his home directory, he do not have to use /home/ but just use below short cuts.

Источник

Linux directory structure: /home and /root folders

This is our 6th post on understanding first level directories in /. Knowing these folders in detail or at least what each is meant for will help you understand Linux/Unix in whole. we already covered below directories, please have a look at those to understand them. In this post we will see two more directories ie /home and /root directory. These directories are meant for similar purpose. The /root is meant for just root user and /home is for all the remaining users.

A brief intro to /home directory in Linux/Unix

The /home directory is a place where by default all user home directories are created.

OK, what are user home directories for?

These directories are a kind of personal place(Working space) for all the users other than root. There will be a separate folder for each user in /home directory. For example if you have a user called ‘Tom’, then his default home directory is /home/tom. We can change this default folder when creating user in Linux. Our Tom user can do what ever he wants in /home/tom folder where he have full rights on the files he created and owned in that folder.

The properties of /home folder?

1) A separate sub folder ie /home/ is present for each user.
2) Only user who owns this sub folder can access it’s content other than root user. So, tom user can not access Barbi user home directory content which is located at /home/barbi.
3) All his terminal properties, command history file, application setting files(

/.ssh) etc everything is located in this folder.
4) System admins when try to implement quota for users they will implement it on /home directory. This /home directory should be mounted on a separate partition.

Each user home directory is important and frequently used directory for that user, we have alias name for it. This alias is set to

so that when ever user wants to navigate to his home directory, he do not have to use /home/ but just use below short cuts.

or

Will take you to your home directory.

When you are in your home directory even our PS1 prompt will show user’s home directory with

Some of the important files which are present in /home/ or /root directory are as below.

1) Bash shell related configuration files.
.bashrc
.bash_history
.bash_profile
.bash_logout

If your shell is not bash then you should see other shell configuration files.

2) Default editor configuration files.
3) You secure shell configuration files are located in

/.ssh which contain your ssh-keys, knownhosts etc.

How about /root directory in Linux?

This is root’s home directory. Do not get confused between / and /root. Both these are meant for different purpose.

/ is the main folder where your file system resides, where as /root is root user home directory. Similar to /home/ , root user saves his personal data, terminal configurations in /root directory.

Читайте также:  Две рабочие группы windows

Some FAQ on user home directories

Why is home directory of root is a separate folder?

Because of security reasons root’s home directory is separated from /home.

I see many users in /etc/passwd but I don’t see them in /home, why?

This can be of two reasons.
1) Either users are system defined users
2) Or users home directory resides some where else.
3) Or intentionally /home directory is not created. For this type of users / will be treated as their home directory. This is a nightmare as he can not do anything in / folder due to lack of permissions.

In our next post we will see lib folder.

Источник

Как узнать домашнюю директорию любого пользователя Linux

Для того, чтобы правильно и безопасно хранить данные на сервере, (особенно, если на этом сервере несколько пользователей), следует точно знать, где располагаются их домашние папки, до которых у пользователей есть доступ (у каждого в свою, но нет доступа в чужие папки с чужими данными). Например, для того, чтобы дать пользователю доступ по ftp только к его данным или подсказать полный путь до его www-директории. В этой статье рассмотрим то, как узнать домашнюю директорию любого пользователя Linux несколькими способами.

Где хранится системная информация о домашних каталогах пользователей в Linux

При создании нового пользователя в Unix-системах, каждому пользователю обязательно домашний каталог. О том, где и как располагается запись о домашней директории пользователя в файле /etc/passwd , подробно описано в → этой статье. Для понимания вопроса сейчас требуется знать, что это предпоследнее (шестое) поле home в строке записи пользователя в этом файле:

login : password : UID : GID : GECOS : home : shell

Поэтому, можно в цикле обходить этот файл в поиске записи нужного пользователя, разбивать строку на подстроки и брать значение 6-го поля. Но это слишком длинный способ. Есть короче и проще. 😉

Команда pwd в Unix

Команда pwd выводит текущий путь к директории, в которой находится пользователь. Выполнив команду pwd , получим этот путь:

У пользователя root в Unix по умолчанию домашней директорией является /root .

Оператор

(тильда) в Debian

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

Результат не сильно отличается от предыдущего, но к

можно добавлять дополнительные пути к папкам и/или файлам пользователя, используя её как точку отсчёта в домашней директории пользователя. Что сильно облегчает работу с написанием относительных путей (относительно не только корня файловой системы, но и корня домашней папки пользователя).

Ещё одним полезным свойством

является то, что с помощью этого оператора можно получить путь до домашней директории любого пользователя в системе (если конечно пользователь есть в системе, то есть прописан в файле /etc/passwd , например посмотреть содержимое домашнего каталога пользователя ftp можно так, поставив перед ним тильду

А теперь посмотреть содержимое этого файла:

Ну и то, к чему мы стремились: посмотреть путь к домашней директории пользователя:

Так гораздо удобнее, чем парсить и разбирать файл /etc/passwd . За нас всю эту работу делает операционная система! 😉

Источник

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