I have wrongly given a wrong home directory to a user. This dir is very critical for my production environment(Can;t afford to lose it for a single minute)
Now i want to delete that user,
Whenever i try to delete user it tries to delete its home dir.
Commnd i use:
userdel
Whenever i try to modify its home, it tries to move data of current home to new home.
Command i use:
usermod
Is there any way to delete the user without deleting its home dir?
Or any other way of coming out of this mess?
The userdel command won't delete the home directory unless you use the -r option. However, if the data is that critical and you could always tar it somewhere before you delete the account just to make absolutely sure. For a production environment I would assume there are tape backups of the server run nightly somewhere as well.
I don't know if putting a # in front of the entry in the /etc/passwd file is a good idea or not. That's of course normal practice to comment out entries in other config files, but /etc/passwd and /etc/shadow can be very sensitive and they're obviously some of the most critical files on the system. Be sure to keep /etc/passwd and /etc/shadow in sync if you do that. If you do edit it manually be sure to run pwconv. Really, I could be wrong on the # on the /etc/passwd file, but in my years of administration I've never seen anyone do that.
Really, I use userdel all the time for deleting users. The userdel command with no options doesn't delete the user's data. Everywhere I've ever worked our standard practice has been to never use the -r option just in case there is anything in that user's home directory that might be needed at a later date. If their home directory was large I will sometimes just tar and gzip it to save space and/or look in there for anything that obviously can be deleted.
And of course all the obvious stuff, make a quick backup of your passwd and shadow files before every modifying them manually. Read the man pages.
I would take option 2 of post #6. Create a new home directory with the correct permissions for the owners uid. Copy passwd and shadow files just in case. Then use "vipw" (not just "vi") to edit the home directory for that user in the passwd file. Run "pwck" (password file checker) afterwards.
userdel should not delete home directory unless specifed with -r option.
bash-3.2# uname -a
SunOS kerber 5.10 Generic_147441-01 i86pc i386 i86pc
bash-3.2# useradd -d /export/home/john -m john
bash-3.2# id john
uid=566(john) gid=1(other)
bash-3.2# finger john
Login name: john
Directory: /export/home/john Shell: /bin/sh
Never logged in.
No unread mail
No Plan.
bash-3.2# ls -lrt /export/home/john
total 3
-rw-r--r-- 1 john other 174 Jan 3 14:24 local.profile
-rw-r--r-- 1 john other 157 Jan 3 14:24 local.login
-rw-r--r-- 1 john other 136 Jan 3 14:24 local.cshrc
bash-3.2# userdel john
bash-3.2# ls -lrt /export/home/john
total 6
-rw-r--r-- 1 566 other 174 Jan 3 14:24 local.profile
-rw-r--r-- 1 566 other 157 Jan 3 14:24 local.login
-rw-r--r-- 1 566 other 136 Jan 3 14:24 local.cshrc
Now that user john no longer exists, you can create it with home directory of your choice.
I agree with Peasant. Similarly "usermod" without the "-m" switch should not try to move the home directory.
I wonder if "userdel" has been aliased on the O/P's system or perhaps intercepted with a script?
It would help to know the Operating System and version of the O/P's system in case it is something unusual or very old.