When creating a new local user on Linux with the useradd and the directory already exists , the following error warning message appears:
useradd: warning: the home directory already exists. Not copying any file from skel directory into it.
If the directory didn’t exist , the Linux useradd process creates the directory and copies the skel files : .kshrc , .bashrc , .bash_profile and .bash_logout files into the user directory.
As a DBA it is not unusual to receive a server with directories already in place. In those situations a scripted approach is required to copy the skel files. A quick and dirty solution is to add the following line after the useradd sequence
cp -r /etc/skel/. /<user_home_directpory>
An example sequence could be :
#add user : db2usr echo "add user = db2usr" useradd -g db2iadm1 -m db2usr -p 'dg8WM/S.o/bAE' -d /db2usr chown db2usr /db2usr #copy skel files cp -r /etc/skel/. /db2usr
Read More
DB2 – Run script on Linux start
Linux Server OS information
DB2 Linux history command
Linux useradd not creating password
Skip to content
In Linux, the useradd
is a command in Linux that is used to add user accounts to your system. The ‘useradd
‘ command is a low-level utility that is used for adding/creating user accounts in Linux and other Unix-like operating systems. The ‘adduser
‘ is much similar to the useradd command because it is just a symbolic link to it. Only root or users with sudo privileges can use the useradd command to create new user accounts. When invoked, useradd
create a new user account according to the options specified on the command line and the default values set in the /etc/default/useradd
file. You can find other guides here :Practical-use-of-SELinux-in-production-how-to-locate-directory-file-context-and-restore-it-with-selinux/, how to create-a-static-pod-in-Kubernetes-with-demos-that-can-help-you-become-a-better-kubernetes-administrator and how to create-and-deliver-a-report-on-system-utilization-on-a-Linux-based-os/.
I previously had a user created in my centOS environment. This user was later deleted and I tried creating a new user with the same name, then this error was prompted. See the image below for more information.
This is actually not an error but just a warning and what this means is.
– Note: Windows does not work like this 🙂 when you delete a user, the user, and the SID is gone unless the user account is recovered.
But in Linux, the home directory is not immediately deleted. All files etc. will still be able for a while. When the system finally deletes the user, the account can be created again.
Note: In windows, when a user is deleted, and a new user is created, a new SID is assigned. This is also the case in Linux as gid and groups id are now different for john as shown below.
I hope you found this blog post helpful. If you have any questions, please let me know in the comment session.
I’m trying to create a new user for my Ubuntu, used this command:
sudo useradd -d /home/dinesh -m ansi
But I keep getting this error
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
Why do I keep getting this error?
Jan 10, 2019
in Linux Administration
by
Dinesh
•
14,394 views
2 answers to this question.
Hey @Dinesh, this isn’t an error, its a warning.
You’re trying to create a new user on the /home/dinesh directory but the system tries to create a new home directory. Hence the warning saying home directory already exists. But if you check your system a new user has already been created. Warnings don’t interrupt like errors.
Hope this helps!
Get your Linux certification today to become certified.
Thanks.
answered
Jan 10, 2019
by
Sitara
selected
Jan 10, 2019
by Kalgi
Related Questions In Linux Administration
- All categories
-
ChatGPT
(11) -
Apache Kafka
(84) -
Apache Spark
(596) -
Azure
(145) -
Big Data Hadoop
(1,907) -
Blockchain
(1,673) -
C#
(141) -
C++
(271) -
Career Counselling
(1,060) -
Cloud Computing
(3,469) -
Cyber Security & Ethical Hacking
(162) -
Data Analytics
(1,266) -
Database
(855) -
Data Science
(76) -
DevOps & Agile
(3,608) -
Digital Marketing
(111) -
Events & Trending Topics
(28) -
IoT (Internet of Things)
(387) -
Java
(1,247) -
Kotlin
(8) -
Linux Administration
(389) -
Machine Learning
(337) -
MicroStrategy
(6) -
PMP
(423) -
Power BI
(516) -
Python
(3,193) -
RPA
(650) -
SalesForce
(92) -
Selenium
(1,569) -
Software Testing
(56) -
Tableau
(608) -
Talend
(73) -
TypeSript
(124) -
Web Development
(3,002) -
Ask us Anything!
(66) -
Others
(2,231) -
Mobile Development
(395) -
UI UX Design
(24)
Subscribe to our Newsletter, and get personalized recommendations.
Already have an account? Sign in.
When creating a new local user on Linux with the useradd and the directory already exists , the following error warning message appears:
useradd: warning: the home directory already exists. Not copying any file from skel directory into it.
If the directory didn’t exist , the Linux useradd process creates the directory and copies the skel files : .kshrc , .bashrc , .bash_profile and .bash_logout files into the user directory.
As a DBA it is not unusual to receive a server with directories already in place. In those situations a scripted approach is required to copy the skel files. A quick and dirty solution is to add the following line after the useradd sequence
cp -r /etc/skel/. /<user_home_directpory>
An example sequence could be :
#add user : db2usr echo "add user = db2usr" useradd -g db2iadm1 -m db2usr -p 'dg8WM/S.o/bAE' -d /db2usr chown db2usr /db2usr #copy skel files cp -r /etc/skel/. /db2usr
Read More
DB2 – Run script on Linux start
Linux Server OS information
DB2 Linux history command
Linux useradd not creating password
Skip to content
In Linux, the useradd
is a command in Linux that is used to add user accounts to your system. The ‘useradd
‘ command is a low-level utility that is used for adding/creating user accounts in Linux and other Unix-like operating systems. The ‘adduser
‘ is much similar to the useradd command because it is just a symbolic link to it. Only root or users with sudo privileges can use the useradd command to create new user accounts. When invoked, useradd
create a new user account according to the options specified on the command line and the default values set in the /etc/default/useradd
file. You can find other guides here :Practical-use-of-SELinux-in-production-how-to-locate-directory-file-context-and-restore-it-with-selinux/, how to create-a-static-pod-in-Kubernetes-with-demos-that-can-help-you-become-a-better-kubernetes-administrator and how to create-and-deliver-a-report-on-system-utilization-on-a-Linux-based-os/.
I previously had a user created in my centOS environment. This user was later deleted and I tried creating a new user with the same name, then this error was prompted. See the image below for more information.
This is actually not an error but just a warning and what this means is.
– Note: Windows does not work like this 🙂 when you delete a user, the user, and the SID is gone unless the user account is recovered.
But in Linux, the home directory is not immediately deleted. All files etc. will still be able for a while. When the system finally deletes the user, the account can be created again.
Note: In windows, when a user is deleted, and a new user is created, a new SID is assigned. This is also the case in Linux as gid and groups id are now different for john as shown below.
I hope you found this blog post helpful. If you have any questions, please let me know in the comment session.
[[email protected] ~]# ls -l /oraeng/app/oracle/product/11.2.0.1
total 0
Before creating user oracle11g
[[email protected] ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
news:x:9:13:news:/etc/news:
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
nscd:x:28:28:NSCD Daemon:/:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
pcap:x:77:77::/var/arpwatch:/sbin/nologin
mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin
smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin
rpc:x:32:32:Portmapper RPC user:/:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:4294967294:4294967294:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
avahi-autoipd:x:100:101:avahi-autoipd:/var/lib/avahi-autoipd:/sbin/nologin
avahi:x:70:70:Avahi daemon:/:/sbin/nologin
distcache:x:94:94:Distcache:/:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
webalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologin
squid:x:23:23::/var/spool/squid:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
named:x:25:25:Named:/var/named:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
amanda:x:33:6:Amanda user:/var/lib/amanda:/bin/bash
ident:x:98:98::/home/ident:/sbin/nologin
pvm:x:24:24::/usr/share/pvm3:/bin/bash
quagga:x:92:92:Quagga routing suite:/var/run/quagga:/sbin/nologin
radvd:x:75:75:radvd user:/:/sbin/nologin
privoxy:x:73:73::/etc/privoxy:/sbin/nologin
uuidd:x:101:104:UUID generator helper daemon:/var/lib/libuuid:/sbin/nologin
ldap:x:55:55:LDAP User:/var/lib/ldap:/bin/false
radiusd:x:95:95:radiusd user:/home/radiusd:/sbin/nologin
pegasus:x:66:65:tog-pegasus OpenPegasus WBEM/CIM services:/var/lib/Pegasus:/sbin/nologin
tomcat:x:91:91:Tomcat:/usr/share/tomcat5:/bin/sh
And after executing the command # useradd -u 1010 -g oinstall -G dba -d /oraeng/app/oracle/product/11.2.0.1 -m oracle11g
only one line added to above
oracle11g:x:1010:1002::/oraeng/app/oracle/product:/bin/bash
and warning as i posted before
[[email protected] ~]# useradd -u 1010 -g oinstall -G dba -d /oraeng/app/oracle/product -m oracle
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
Regards,
Arya
Здравствуйте, у меня возникла проблема с добавлением новых пользователей в CentOS с помощью скриптов.
Добавить пользователя можно следующим образом:
useradd -g ftp-users -d /home/ftp-docs -p crypted_password login
Для использования этой команды я создал небольшой php-скрипт:
<?php
system(«useradd -g ftp-users -d /home/ftp-docs -p ».crypt($argv[2]).» «.$argv[1]);
?>
При вводе в консоле: php add_user.php test_user_mir testpassword
Пользователь создается и выводится сообщение:
ng: the home directory already exists.
Not copying any file from skel directory into it.
После этой команды пользователь действительно создаётся, но не удаётся его использовать.
При ручном создании пользователя, я делаю следующее:
1. Прописываю в консоле useradd -g ftp-users -d /home/ftp-docs login
2. Прописываю пароль пользователю с помощью команды passwd login
После этих действий можно использовать данный логин для соединение с фтп-сервером.
Но, когда я делаю это с помощью скрипта, я не могу соединиться с фтп-сервером:
Команда: USER login_created_by_script
Ответ: 331 Please specify the password.
Команда: PASS ************
Ответ: 530 Login incorrect.
Ошибка: Критическая ошибка
Ошибка: Невозможно подключиться к серверу
Хотя в списке пользователей данный логин присутствует.
Буду благодарен за любую помощь в решении данной проблемы.
A CentOS 7 server needs to have a new user created with a specific home directory and shell defined as follows, taken from the instructions at this link:
sudo /usr/sbin/useradd --create-home --home-dir /opt/atlassian/bitbucket --shell /bin/bash atlbitbucket
However, when that command is run on a CentOS 7 server, the command fails with the following error:
useradd: cannot create directory /opt/atlassian/bitbucket
Similarly, creating the /opt/atlassian/bitbucket
directory before-hand results in the following error:
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
What specific changes need to be made to these commands, so that the new atlbitbucket
user can successfully be created?
The Complete Terminal Output:
The following is the complete series of commands and responses in the CentOS 7 terminal:
Manually Creating The Directories:
login as: my_sudoer_user
my_sudoer_user@private.lan.ip.addr's password:
Last login: Mon May 15 14:00:18 2017
[my_sudoer_user@localhost ~]$ sudo mkdir /opt/atlassian/
[sudo] password for my_sudoer_user:
[my_sudoer_user@localhost ~]$ sudo mkdir /opt/atlassian/bitbucket
[my_sudoer_user@localhost ~]$ sudo /usr/sbin/useradd --create-home --home-dir /opt/atlassian/bitbucket --shell /bin/bash atlbitbucket
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
[my_sudoer_user@localhost ~]$ sudo rmdir /opt/atlassian/bitbucket
[my_sudoer_user@localhost ~]$ sudo rmdir /opt/atlassian/
The Recommended useradd
Syntax:
[my_sudoer_user@localhost ~]$ sudo /usr/sbin/useradd --create-home --home-dir /opt/atlassian/bitbucket --shell /bin/bash atlbitbucket
useradd: user 'atlbitbucket' already exists
[my_sudoer_user@localhost ~]$ sudo userdel -r atlbitbucket
userdel: atlbitbucket home directory (/opt/atlassian/bitbucket) not found
[my_sudoer_user@localhost ~]$ sudo /usr/sbin/useradd --create-home --home-dir /opt/atlassian/bitbucket --shell /bin/bash atlbitbucket
useradd: cannot create directory /opt/atlassian/bitbucket
[my_sudoer_user@localhost ~]$
adduser
Instead Of useradd
I then tried @terdon’s suggestion from this other posting to use adduser
instead, but got the same error, as follows:
[my_sudoer_user@localhost ~]$ sudo userdel -r atlbitbucket
[sudo] password for my_sudoer_user:
userdel: atlbitbucket mail spool (/var/spool/mail/atlbitbucket) not found
userdel: atlbitbucket home directory (/opt/atlassian/bitbucket) not found
[my_sudoer_user@localhost ~]$ sudo adduser --create-home --home-dir /opt/atlassian/bitbucket --shell /bin/bash atlbitbucket
adduser: cannot create directory /opt/atlassian/bitbucket
[my_sudoer_user@localhost ~]$
Shorter Syntax:
Then I tried @rajcoumar’s suggestion from the same other posting, but got the same following results:
[my_sudoer_user@localhost ~]$ sudo userdel -r atlbitbucket
userdel: atlbitbucket mail spool (/var/spool/mail/atlbitbucket) not found
userdel: atlbitbucket home directory (/opt/atlassian/bitbucket) not found
[my_sudoer_user@localhost ~]$ sudo useradd -m -d /opt/atlassian/bitbucket -s /bin/bash atlbitbucket
useradd: cannot create directory /opt/atlassian/bitbucket
[my_sudoer_user@localhost ~]$
Elevating To root
:
I even upgraded to root
just to see if the problem could be resolved by running the command as root, but I still got the following error:
[my_sudoer_user@localhost ~]$ su -
Password:
Last login: Mon May 15 14:07:11 PDT 2017 on ttyS0
[root@localhost ~]# /usr/sbin/useradd --create-home --home-dir /opt/atlassian/bitbucket --shell /bin/bash atlbitbucket
useradd: cannot create directory /opt/atlassian/bitbucket
[root@localhost ~]#
I’m trying to add users to an existing directory but I keep getting:
useradd: warning: the home directory already exists. Not copying any file from skel directory into it.
I want to add users to the /home/test
directory; I know this isn’t a good thing to do and there are many reasons why I shouldn’t do it, but I need to do it anyway.
I want to add the user alex
to the existing directory and ralf
, so I tried to change the permission of the folders so users can access it:
chmod -R 777 /home/test
And add the user to the folder:
useradd -m -d /home/test ralf
But when I try to switch to the new user it shows this:
I think it is a permission issue but I am not too sure.