- How to Create Home Directory for Existing User in Linux
- Create default home directory for existing user
- Conclusion
- Linux directory structure: /home and /root folders
- A brief intro to /home directory in Linux/Unix
- OK, what are user home directories for?
- The properties of /home folder?
- How about /root directory in Linux?
- Some FAQ on user home directories
- Linux directory structure: /home and /root folders
- A brief intro to /home directory in Linux/Unix
- OK, what are user home directories for?
- The properties of /home folder?
- Command to change the default home directory of a user [closed]
- 7 Answers 7
- Change the user’s home directory:
- Change the user’s home directory + Move the contents of the user’s current directory:
- Not the answer you’re looking for? Browse other questions tagged linux shell unix or ask your own question.
- Linked
- Related
- Hot Network Questions
- How can I retrospectively create a default home directory for an existing user in terminal?
- 5 Answers 5
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.
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 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.
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 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
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.
Источник
Command to change the default home directory of a user [closed]
Want to improve this question? Update the question so it’s on-topic for Stack Overflow.
Closed 9 months ago .
I would like to know whether there is any simple shell command to change the user home directory in Linux/Unix (one similar to chsh which changes the default login shell of an existing valid user) without touching the /etc/passwd file. Thanks
7 Answers 7
Ibrahim’s comment on the other answer is the correct way to alter an existing user’s home directory.
Change the user’s home directory:
usermod is the command to edit an existing user.
-d (abbreviation for —home ) will change the user’s home directory.
Change the user’s home directory + Move the contents of the user’s current directory:
-m (abbreviation for —move-home ) will move the content from the user’s current directory to the new directory.
Simply open this file using a text editor, type:
The default home directory defined by HOME variable, find line that read as follows:
Save and close the file. Now you can add user using regular useradd command:
Verify user information:
The accepted answer is faulty, since the contents from the initial user folder are not moved using it. I am going to add another answer to correct it:
You don’t need to create the folder with username and this will also move your files from the initial user folder to /newhome/username folder.
In case other readers look for information on the adduser command.
Set DHOME variable
Found out that this breaks some applications, the better way to do it is
In addition to symlink, on more recent distros and filesystems, as root you can also use bind-mount:
This is useful for allowing access «through» the /home directory to subdirs via daemons that are otherwise configured to avoid pathing through symlinks (apache, ftpd, etc.).
You have to remember (or init script) to bind upon restarts, of course.
An example init script in /etc/fstab is
You can do it with:
Edit the user home directory and then move the required files and directories to it:
Set the correct permission
usermod -m -d /newhome username
Not the answer you’re looking for? Browse other questions tagged linux shell unix or ask your own question.
Linked
Related
Hot Network Questions
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.10.8.40416
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Источник
How can I retrospectively create a default home directory for an existing user in terminal?
I created a user without a home directory and now I want to create a home directory for them. Not just a folder called /home/new-user , but a complete default home directory with all the normal folders and hidden files, etc.
How can I do that?
5 Answers 5
Use the following (as root, or with sudo if not root):
For this to work, folder /home/username must not exist.
For X-related folders (Desktop, Downloads, etc), you will need to login in a graphics environment; they will be automatically generated the first time you login.
The subdirectories (Documents, Downloads, etc. ) are automatically created when the user first logs in through GNOME, provided that the home directory is created with the correct permissions. Here’s a demonstration:
You can check that the user’s home directory is correctly set by checking the entry in /etc/passwd . You should, by default, see the home directory set to /home/testinguser :
If you don’t see the home directory /home/testinguser there, you’ll need to execute the command sudo usermod -d /home/testinguser testinguser to update it, although you should not need to use this command because it should be set by default (according to useradd ‘s manpages).
I then logged out of my account, and logged back in with testinguser , and here are the subdirectories automatically created:
I didn’t need to copy the contents of /etc/skel .
If possible, can you please try following these steps, creating another new user? Once you’re done, you can remove this new user by sudo deluser testinguser && sudo rm -r /home/testinguser .
If all of this did not work with you, then I’m guessing it’s a bug.
Источник