Why do I get error "Could not chdir to home directory"
Solution 1
First the easy question, why is my shell name -bash-4.1$
. The technical name for what you call the shell name is the "command prompt". With bash that is set via the environment variable PS1
. If PS1 is not set in your environment bash defaults to showing the bash version as your prompt. (See the ENVIRONMENT
section of the bash man page for more details on environment, and Shell Variables
for a list of the ones it provides by default). If you want it to display bob
(I assume you are used to it displaying the working directory) you can use:
PS1='\W$ '
See the PROMPTING
section of the bash manual to see what else can be set in the bash prompt.
I suspect the Unable to create and initialize directory
and Input/output error
point to a failed hard disk drive, a powered off external USB drive or, if you use NIS/NIS+ to automount, an NFS issue (directories under /foobar/users may be automounted).
You can see what file system the /foobar/users
path live under by examining the output of the mount
command which will inform you what devices provide which parts of the filesystem. It will inform you here as to where /foobar is mounted from. If /foobar is not listed then it's the / directory that is having I/O errors and it most likely is a failed disk. You can also filter mount by file system types mount -t nfs
shows all nfs drives mount -t ext3
will show all ext3fs mount points and so on. man mount
and looking at the -t
option will show what filesystems are supported.
Once you have found out what device the directory lives on you can then have a better idea of how to diagnose the issue (if it's something like /dev/sda1 or similar) it is a hard disk drive and you can start looking for errors in the systems log files grep sda1 /var/log/syslog
. If it's NFS you man need to remount the drive, or restart the NFS services.
Solution 2
Your first login fails to create the home directory and after that the system fails to step into that directory. This is simply because there is no error checking if the directory creation was successful. You need to ask your sysadmins to investigate why the folder creation fails.
Solution 3
“Input/output error” indicates something wrong with the filesystem driver. It could be a driver bug or a hardware error. If cd
had reported “no such file or directory”, it could indicate a bug in the home directory creation script, but “Input/output error” from cd
indicates something deeper. Contact your system administrator.
The shell prompt is bash-4.1$
instead of what you're used to because your home directory couldn't be opened, so your .bashrc
(which presumably sets a different prompt) isn't read.
Related videos on Youtube
Tony Anderson
Automation Engineer Deving all of the Ops in Lehi, Utah. Primarily focused in: Puppet Chef Docker #SOreadytohelp
Updated on September 18, 2022Comments
-
Tony Anderson over 1 year
I work in support, and occasionally I'm given shell access to a remote Linux system.
I frequently find that when the admin gives me remote access, that I get the following output upon login.
[joe@mycomputer ~]$ ssh [email protected] [email protected] password: Creating directory '/foobar/users/bob'. Unable to create and initialize directory '/foobar/users/bob'. Last login: Mon Jul 29 13:05:27 2013 from bar.edu Could not chdir to home directory /foobar/users/bob: Input/output error -bash: /foobar/users/bob/.bash_profile: Input/output error -bash-4.1$ -bash-4.1$ echo $HOME /foobar/users/bob
The admins I interact with know way more about Linux than I do. My questions are:
-
Why do I get "Unable to initialize directory"?
- Is that an error on their part, or is that intentional for security? I'm assuming they ran
useradd bob
without the -m option when they created my account.
- Is that an error on their part, or is that intentional for security? I'm assuming they ran
Why is my shell name 'bash-4.1' and not 'bob'?
Update
I'm guessing that because I am not a normal user on the system, I don't have a network share foobar/users, just local storage. It seems strange that such a high percentage of servers I log into would configure their server the same way.
Resources I have investigated
-
Tim almost 11 years
Unable to create and initialize directory '/foobar/users/bob'.
is the key. Since the folder isn't created your shell cannot chdir to that path since it doesn't exist. The lack of a home folder means no user specific bash profile, so you are defaulting to the default global bash profile that doesn't use the hostname or username in the bash prompt. -
slm almost 11 yearsAsk the Bonus question as it's own question. Then take it out of this question. Too much for one question makes them less valuable down the road and harder to answer/address for people in general.
-
Tony Anderson almost 11 yearsThanks @slm I edited this question, and created a new one unix.stackexchange.com/questions/85891/…
-
slm almost 11 yearsRelated: unix.stackexchange.com/questions/39905/…. I think @jordanm is correct that this means there's an issue with the underlying HDD.
-
-
jordanm almost 11 yearsInput/output error indicates a drive failure or perhaps an NFS problem.