- Linux Change Default User Home Directory While Adding A New User
- How Do I Change Existing User’s Home Directory?
- 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 to Create Home Directory for Existing User in Linux
- Create default home directory for existing user
- Conclusion
- Users and groups
- Contents
- Overview
- Permissions and ownership
- Shadow
- File list
- User management
- Example adding a user
- Example adding a system user
- Change a user’s login name or home directory
- Other examples of user management
- User database
- Automatic integrity checks
- Group management
- Group list
- User groups
- System groups
- Pre-systemd groups
- Unused groups
- Other tools related to these databases
Linux Change Default User Home Directory While Adding A New User
B y default base directory for the system user is set to /home directory. I’d like to add user to /iscsi/home/$
Default values for account creation defined in /etc/default/useradd file under CentOS / RHEL / Fedora / Debian / Ubuntu and other Linux distros. Simply open this file using a text editor, type:
# vi /etc/default/useradd
The default home directory defined by HOME variable, find line that read as follows:
HOME=/home
Replace with:
HOME=/iscsi/user
Save and close the file. Now you can add user using regular useradd command:
# useradd vivek
# passwd vivek
Verify user information:
# finger vivek
Output:
How Do I Change Existing User’s Home Directory?
You need to use the usermod command to set the user’s new login directory. The syntax is as follows:
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
- -d dirnanme : Path to new login (home) directory.
- -m : The contents of the current home directory will be moved to the new home directory, which is created if it does not already exist.
In this example set the user’s new login directory to /users/v/vivek from /home/vivek, enter:
# usermod -m -d /users/v/vivek vivek
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Category | List of Unix and Linux commands |
---|---|
Documentation | help • mandb • man • pinfo |
Disk space analyzers | df • duf • ncdu • pydf |
File Management | cat • cp • less • mkdir • more • tree |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Linux Desktop Apps | Skype • Spotify • VLC 3 |
Modern utilities | bat • exa |
Network Utilities | NetHogs • dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop |
Searching | ag • grep • whereis • which |
Shell builtins | compgen • echo • printf |
Text processing | cut • rev |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Comments on this entry are closed.
or specify the home with -d in useradd command
Nice…info…but it doesnt work ;_( it still gives same error as before changeing in /etc/default/usradd
]# useradd -d /root/lvm/ mas
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
Hi All,
Anyone who can teach me the solution for this problem:
I add a user jayabellon using this command:
useradd -u 888 -g oinstall -G dba -d /home/jayabellon -r jayabellon
i forgot to create home directory when I log-In so it prompts me cannot go to that directory.
I deleted the user and retry to create again.
But still, when I log-In, this is what it looks like:
-bash-3.00$
I am expecting it to be
[user@hostname]$
this is my entry in /etc/passwd:
jayabellon:x:888:501:jayabellon:/home/jayabellon:/bin/bash
actually, i am only working in a test server. Nothing much critical on this one.
It’s just that its my first time to create user using command line, because i usually do it in GUI based.
Even I have the same problem. If you get any solution please mail me. One solution I can give that re-install the operating system,even I did the same.
-bash-3.00$ finger jayabellon
Login: jayabellon Name: jayabellon
Directory: /home/jayabellon Shell: /bin/bash
Never logged in.
No mail.
No Plan.
Pass -m option to useradd command to create users home dir.
it’s in man page also.
found that it’s faster to create user in command line rather than using GUI Administration tool.
Any chance you can provide a similar command for Oracle SQL?
Thanks. I’ve been wondering how to change the default home directory for a while now. Glad I found this to explain how.
Your comment is awaiting moderation.
This is just nonsense of a blog, when the same thing can be achieved with usermod command with -d option to change the home directory.
It’s really not “nonsense of a blog.” The whole point is so that it is a default, so you DON’T have to do the -d option every time. Why make things harder on yourself? Set all the defaults in the config files, and then just useradd and be done with it.
home directory already exits.
not copying any file from skel directory into it
when i login to oracle user it show me
-bash-3.00$
Thanks a lot you saved me.. since the syntax was so complicated..
what i did wrong was while trying to change existing username to new one..
I was logged as root since it’s not good to change username while being logged under it.. everything went smooth i even appended the groups to my new user but since i didn’t specify the path to the new home directory after -dm all of the old folder was moved by default to the root folder instead of home since i was logged as root.. so be careful guys to specify path or just log into any other user you have that has folder in home$ or i guess excute the command in the target folder .. here what i used to change username:
usermod -dm -Ga ,sudo -l
to understand this go to the man page..
sorry but trying to add syntax with but gets deleted.
add this to first comment
forgot to mention that combining options letters won’t work which i guess is weird since it;s used in tar -vzf … but i guess some commands don’t agree.. thanks again i’ve just moved my whole folders to the destination.. u r the best not even the man instructions since those are stupid for not giving no examples.. thanks again guys..
Thanks for the article.
When changing the default home dir in /etc/default/useradd, I suggest to change it in /etc/adduser.conf as well (variable DHOME) – otherwise users added by the command ‘adduser’ will have the wrong/old home still.
Regards
on rhel 5 I had to change the command slightly
usermod -d /users/v/vivek -m vivek
this applies to centos 5 as well
it’s working both combination of -m -d options
it’s working both combination of -m -d options
usermod -m -d
I tried too many times but it’s telling me that my user is used by a process 3284
I created a user using adduser :
useradd sacadmin
and added it to a group alcatel.
Now when I do su sacadmin it logs in, but there is no directory /sacadmin in /users.
I need a directory in users for this user and a bin in it like /users/sscadmin/bin
can we Modify Oracle_Base directory to other new directory after installation. Plz help me
change home directory in user1
cmd
#usermod -m -d /backup user1
usermod: user user1 is currently logged in
what is solve
Logout users1. Or kill user1 session:
pkill -KILL -u user1
Источник
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.
Источник
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.
Источник
Users and groups
Users and groups are used on GNU/Linux for access control—that is, to control access to the system’s files, directories, and peripherals. Linux offers relatively simple/coarse access control mechanisms by default. For more advanced options, see ACL, Capabilities and PAM#Configuration How-Tos.
Contents
Overview
A user is anyone who uses a computer. In this case, we are describing the names which represent those users. It may be Mary or Bill, and they may use the names Dragonlady or Pirate in place of their real name. All that matters is that the computer has a name for each account it creates, and it is this name by which a person gains access to use the computer. Some system services also run using restricted or privileged user accounts.
Managing users is done for the purpose of security by limiting access in certain specific ways. The superuser (root) has complete access to the operating system and its configuration; it is intended for administrative use only. Unprivileged users can use the su and sudo programs for controlled privilege elevation.
Any individual may have more than one account as long as they use a different name for each account they create. Further, there are some reserved names which may not be used such as «root».
Users may be grouped together into a «group», and users may be added to an existing group to utilize the privileged access it grants.
Permissions and ownership
The UNIX operating system crystallizes a couple of unifying ideas and concepts that shaped its design, user interface, culture and evolution. One of the most important of these is probably the mantra: «everything is a file,» widely regarded as one of the defining points of UNIX. This key design principle consists of providing a unified paradigm for accessing a wide range of input/output resources: documents, directories, hard-drives, CD-ROMs, modems, keyboards, printers, monitors, terminals and even some inter-process and network communications. The trick is to provide a common abstraction for all of these resources, each of which the UNIX fathers called a «file.» Since every «file» is exposed through the same API, you can use the same set of basic commands to read/write to a disk, keyboard, document or network device.
A fundamental and very powerful, consistent abstraction provided in UNIX and compatible operating systems is the file abstraction. Many OS services and device interfaces are implemented to provide a file or file system metaphor to applications. This enables new uses for, and greatly increases the power of, existing applications — simple tools designed with specific uses in mind can, with UNIX file abstractions, be used in novel ways. A simple tool, such as cat, designed to read one or more files and output the contents to standard output, can be used to read from I/O devices through special device files, typically found under the /dev directory. On many systems, audio recording and playback can be done simply with the commands, » cat /dev/audio > myfile » and » cat myfile > /dev/audio ,» respectively.
Every file on a GNU/Linux system is owned by a user and a group. In addition, there are three types of access permissions: read, write, and execute. Different access permissions can be applied to a file’s owning user, owning group, and others (those without ownership). One can determine a file’s owners and permissions by viewing the long listing format of the ls command:
The first column displays the file’s permissions (for example, the file initramfs-linux.img has permissions -rw-r—r— ). The third and fourth columns display the file’s owning user and group, respectively. In this example, all files are owned by the root user and the root group.
In this example, the sf_Shared directory is owned by the root user and the vboxsf group. It is also possible to determine a file’s owners and permissions using the stat command:
Access permissions are displayed in three groups of characters, representing the permissions of the owning user, owning group, and others, respectively. For example, the characters -rw-r—r— indicate that the file’s owner has read and write permission, but not execute ( rw- ), whilst users belonging to the owning group and other users have only read permission ( r— and r— ). Meanwhile, the characters drwxrwx— indicate that the file’s owner and users belonging to the owning group all have read, write, and execute permissions ( rwx and rwx ), whilst other users are denied access ( — ). The first character represents the file’s type.
List files owned by a user or group with the find utility:
A file’s owning user and group can be changed with the chown (change owner) command. A file’s access permissions can be changed with the chmod (change mode) command.
Shadow
The user, group and password management tools on Arch Linux come from the shadow package, which is a dependency of the base meta package.
File list
File | Purpose |
---|---|
/etc/shadow | Secure user account information |
/etc/passwd | User account information |
/etc/gshadow | Contains the shadowed information for group accounts |
/etc/group | Defines the groups to which users belong |
User management
To list users currently logged on the system, the who command can be used. To list all existing user accounts including their properties stored in the user database, run passwd -Sa as root. See passwd(1) for the description of the output format.
To add a new user, use the useradd command:
-m / —create-home the user’s home directory is created as /home/username . The directory is populated by the files in the skeleton directory. The created files are owned by the new user. -G / —groups a comma separated list of supplementary groups which the user is also a member of. The default is for the user to belong only to the initial group. -s / —shell a path to the user’s login shell. Ensure the chosen shell is installed if choosing something other than Bash.
If an initial login group is specified by name or number, it must refer to an already existing group. If not specified, the behaviour of useradd will depend on the USERGROUPS_ENAB variable contained in /etc/login.defs . The default behaviour ( USERGROUPS_ENAB yes ) is to create a group with the same name as the username.
When the login shell is intended to be non-functional, for example when the user account is created for a specific service, /usr/bin/nologin may be specified in place of a regular shell to politely refuse a login (see nologin(8) ).
See useradd(8) for other supported options.
Example adding a user
To add a new user named archie , creating its home directory and otherwise using all the defaults in terms of groups, folder names, shell used and various other parameters:
Although it is not required to protect the newly created user archie with a password, it is highly recommended to do so:
The above useradd command will also automatically create a group called archie and makes this the default group for the user archie . Making each user have their own group (with the group name same as the user name) is the preferred way to add users.
You could also make the default group something else using the -g option, but note that, in multi-user systems, using a single default group (e.g. users ) for every user is not recommended. The reason is that typically, the method for facilitating shared write access for specific groups of users is setting user umask value to 002 , which means that the default group will by default always have write access to any file you create. See also User Private Groups. If a user must be a member of a specific group specify that group as a supplementary group when creating the user.
In the recommended scenario, where the default group has the same name as the user name, all files are by default writeable only for the user who created them. To allow write access to a specific group, shared files/folders can be made writeable by default for everyone in this group and the owning group can be automatically fixed to the group which owns the parent directory by setting the setgid bit on this directory:
Otherwise the file creator’s default group (usually the same as the user name) is used.
If a GID change is required temporarily you can also use the newgrp command to change the user’s default GID to another GID at runtime. For example, after executing newgrp groupname files created by the user will be associated with the groupname GID, without requiring a re-login. To change back to the default GID, execute newgrp without a groupname.
Example adding a system user
System users can be used to run processes/daemons under a different user, protecting (e.g. with chown) files and/or directories and more examples of computer hardening.
With the following command a system user without shell access and without a home directory is created (optionally append the -U parameter to create a group with the same name as the user, and add the user to this group):
If the system user requires a specific user and group ID, specify them with the -u / —uid and -g / —gid options when creating the user:
Change a user’s login name or home directory
To change a user’s home directory:
The -m option also automatically creates the new directory and moves the content there.
Make sure there is no trailing / on /my/old/home .
To change a user’s login name:
Changing a username is safe and easy when done properly, just use the usermod command. If the user is associated to a group with the same name, you can rename this with the groupmod command.
Alternatively, the /etc/passwd file can be edited directly, see #User database for an introduction to its format.
Also keep in mind the following notes:
- If you are using sudo make sure you update your /etc/sudoers to reflect the new username(s) (via the visudo command as root).
- Personal crontabs need to be adjusted by renaming the user’s file in /var/spool/cron from the old to the new name, and then opening crontab -e to change any relevant paths and have it adjust the file permissions accordingly.
- Wine’s personal folders/files’ contents in
/.local/share/applications/wine/Programs and possibly more need to be manually renamed/edited.
or $HOME variables for home directories.
Other examples of user management
To enter user information for the GECOS comment (e.g. the full user name), type:
(this way chfn runs in interactive mode).
Alternatively the GECOS comment can be set more liberally with:
To mark a user’s password as expired, requiring them to create a new password the first time they log in, type:
User accounts may be deleted with the userdel command:
The -r option specifies that the user’s home directory and mail spool should also be deleted.
To change the user’s login shell:
User database
Local user information is stored in the plain-text /etc/passwd file: each of its lines represents a user account, and has seven fields delimited by colons.
- account is the user name. This field can not be blank. Standard *NIX naming rules apply.
- password is the user password.
Broken down, this means: user jack , whose password is in /etc/shadow , whose UID is 1001 and whose primary group is 1003. Jack Smith is his full name and there is a comment associated to his account; his home directory is /home/jack and he is using Bash.
The pwck command can be used to verify the integrity of the user database. It can sort the user list by GID at the same time, which can be helpful for comparison:
Automatic integrity checks
Instead of running pwck / grpck manually, the systemd timer shadow.timer , which is part of, and is enabled by, installation of the shadow package, will start shadow.service daily. shadow.service will run pwck(8) and grpck(8) to verify the integrity of both password and group files.
If discrepancies are reported, group can be edited with the vigr(8) command and users with vipw(8) . This provides an extra margin of protection in that these commands lock the databases for editing. Note that the default text editor is vi, but an alternative editor will be used if the EDITOR environment variable is set, then that editor will be used instead.
Group management
/etc/group is the file that defines the groups on the system (see group(5) for details). There is also its companion gshadow which is rarely used. Its details are at gshadow(5) .
Display group membership with the groups command:
If user is omitted, the current user’s group names are displayed.
The id command provides additional detail, such as the user’s UID and associated GIDs:
To list all groups on the system:
Create new groups with the groupadd command:
Add users to a group with the gpasswd command (see FS#58262 regarding errors):
Alternatively, add a user to additional groups with usermod (replace additional_groups with a comma-separated list):
Modify an existing group with the groupmod command, e.g. to rename the old_group group to new_group :
To delete existing groups:
To remove users from a group:
The grpck command can be used to verify the integrity of the system’s group files.
Group list
This section explains the purpose of the essential groups from the filesystem package. There are many other groups, which will be created with correct GID when the relevant package is installed. See the main page for the software for details.
User groups
Non-root workstation/desktop users often need to be added to some of following groups to allow access to hardware peripherals and facilitate system administration:
Group | Affected files | Purpose |
---|---|---|
adm | Administration group, commonly used to give read access to protected logs. It has full read access to journal files. | |
ftp | /srv/ftp/ | Access to files served by FTP servers. |
games | /var/games | Access to some game software. |
http | /srv/http/ | Access to files served by HTTP servers. |
log | Access to log files in /var/log/ created by syslog-ng. | |
rfkill | /dev/rfkill | Right to control wireless devices power state (used by rfkill). |
sys | Right to administer printers in CUPS. | |
systemd-journal | /var/log/journal/* | Can be used to provide read-only access to the systemd logs, as an alternative to adm and wheel [1]. Otherwise, only user generated messages are displayed. |
uucp | /dev/ttyS1+ , /dev/tts/8+ , /dev/ttyUSB5+ , /dev/ttyACM5+ , /dev/rfcomm5+ | RS-232 serial ports and devices connected to them. |
wheel | Administration group, commonly used to give privileges to perform administrative actions. It has full read access to journal files and the right to administer printers in CUPS. Can also be used to give access to the sudo and su utilities (neither uses it by default). |
System groups
The following groups are used for system purposes, an assignment to users is only required for dedicated purposes:
Group | Affected files | Purpose |
---|---|---|
dbus | used internally by dbus | |
kmem | /dev/port , /dev/mem , /dev/kmem | |
locate | /usr/bin/locate , /var/lib/locate , /var/lib/mlocate , /var/lib/slocate | See Locate. |
lp | /dev/lp9* , /dev/parport8* | Access to parallel port devices (printers and others). |
/usr/bin/mail | ||
nobody | Unprivileged group. | |
proc | /proc/pid/ | A group authorized to learn processes information otherwise prohibited by hidepid= mount option of the proc file system. The group must be explicitly set with the gid= mount option. |
root | /* | Complete system administration and control (root, admin). |
smmsp | sendmail group. | |
tty | /dev/tty , /dev/vcc , /dev/vc , /dev/ptmx | |
utmp | /run/utmp , /var/log/btmp , /var/log/wtmp |
Pre-systemd groups
Before arch migrated to systemd, users had to be manually added to these groups in order to be able to access the corresponding devices. This way has been deprecated in favour of udev marking the devices with a uaccess tag and logind assigning the permissions to users dynamically via ACLs according to which session is currently active. Note that the session must not be broken for this to work (see General troubleshooting#Session permissions to check it).
There are some notable exceptions which require adding a user to some of these groups: for example if you want to allow users to access the device even when they are not logged in. However, note that adding users to the groups can even cause some functionality to break (for example, the audio group will break fast user switching and allows applications to block software mixing).
Group | Affected files | Purpose |
---|---|---|
audio | /dev/audio , /dev/snd/* , /dev/rtc0 | Direct access to sound hardware, for all sessions. It is still required to make ALSA and OSS work in remote sessions, see ALSA#User privileges. Also used in JACK to give users realtime processing permissions. |
disk | /dev/sd[a-zA-Z]*8* | Access to block devices not affected by other groups such as optical , floppy , and storage . |
floppy | /dev/fd9* | Access to floppy drives. |
input | /dev/input/event2* , /dev/input/mouse8* | Access to input devices. Introduced in systemd 215 [2]. |
kvm | /dev/kvm | Access to virtual machines using KVM. |
optical | /dev/sr5 , /dev/sg9 | Access to optical devices such as CD and DVD drives. |
scanner | /var/lock/sane | Access to scanner hardware. |
storage | /dev/st8*[lma]* , /dev/nst6*[lma]* | Used to gain access to removable drives such as USB hard drives, flash/jump drives, MP3 players; enables the user to mount storage devices.[3] Now solely for direct access to tapes if no custom udev rules is involved.[4][5][6][7] |
video | /dev/fb/0 , /dev/misc/agpgart | Access to video capture devices, 2D/3D hardware acceleration, framebuffer (X can be used without belonging to this group). |
Unused groups
The following groups are currently not used for any purpose:
Group | Affected files | Purpose |
---|---|---|
bin | none | Historical |
daemon | ||
lock | Used for lockfile access. Required by e.g. gnokii AUR . | |
mem | ||
network | Unused by default. Can be used e.g. for granting access to NetworkManager (see NetworkManager#Set up PolicyKit permissions). | |
power | ||
uuidd | ||
users | The primary group for users when user private groups are not used (generally not recommended), e.g. when creating users with USERGROUPS_ENAB no in /etc/login.defs or the -N / —no-user-group option of useradd. |
Other tools related to these databases
This article or section is a candidate for merging with #Shadow.
The factual accuracy of this article or section is disputed.
getent(1) can be used to read a particular record.
As warned in #User database, using specific utilities such as passwd and chfn , is a better way to change the databases. Nevertheless, there are times when editing them directly is looked after. For those times, vipw , vigr are provided. It is strongly recommended to use these tailored editors over using a general text editor as they lock the databases against concurrent editing. They also help prevent invalid entries and/or syntax errors. Note that Arch Linux prefers usage of specific tools, such as chage, for modifying the shadow database over using vipw -s and vigr -s from util-linux . See also FS#31414.
Источник