Determining home dir of a user
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I need to know how home directory for a linux user is determined. Everyone's answer would be "hey, look at /etc/passwd
and find it out". But this seems not to be always correct. Look at this:
$ whoami
test
$ cat /etc/passwd
test:x:2000:2000::/home/test:/bin/bash (relevant line)
$ echo ~
/root
$ cd
bash: cd: /root: No such file or directory
I really have no idea what is going on. It is a subsystem which I entered as root by chroot --userspec=test path/to/subsystem/ /bin/bash
. Does anyone know what this is and how to fix it so that ~
expands to /home/test
and cd
works as expected?
users chroot home
add a comment |Â
up vote
3
down vote
favorite
I need to know how home directory for a linux user is determined. Everyone's answer would be "hey, look at /etc/passwd
and find it out". But this seems not to be always correct. Look at this:
$ whoami
test
$ cat /etc/passwd
test:x:2000:2000::/home/test:/bin/bash (relevant line)
$ echo ~
/root
$ cd
bash: cd: /root: No such file or directory
I really have no idea what is going on. It is a subsystem which I entered as root by chroot --userspec=test path/to/subsystem/ /bin/bash
. Does anyone know what this is and how to fix it so that ~
expands to /home/test
and cd
works as expected?
users chroot home
Related post: Chrooted user does not start in his home directory and does not load his bash_profiles
â igal
Oct 19 '17 at 23:56
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I need to know how home directory for a linux user is determined. Everyone's answer would be "hey, look at /etc/passwd
and find it out". But this seems not to be always correct. Look at this:
$ whoami
test
$ cat /etc/passwd
test:x:2000:2000::/home/test:/bin/bash (relevant line)
$ echo ~
/root
$ cd
bash: cd: /root: No such file or directory
I really have no idea what is going on. It is a subsystem which I entered as root by chroot --userspec=test path/to/subsystem/ /bin/bash
. Does anyone know what this is and how to fix it so that ~
expands to /home/test
and cd
works as expected?
users chroot home
I need to know how home directory for a linux user is determined. Everyone's answer would be "hey, look at /etc/passwd
and find it out". But this seems not to be always correct. Look at this:
$ whoami
test
$ cat /etc/passwd
test:x:2000:2000::/home/test:/bin/bash (relevant line)
$ echo ~
/root
$ cd
bash: cd: /root: No such file or directory
I really have no idea what is going on. It is a subsystem which I entered as root by chroot --userspec=test path/to/subsystem/ /bin/bash
. Does anyone know what this is and how to fix it so that ~
expands to /home/test
and cd
works as expected?
users chroot home
asked Oct 19 '17 at 23:14
karlosss
20416
20416
Related post: Chrooted user does not start in his home directory and does not load his bash_profiles
â igal
Oct 19 '17 at 23:56
add a comment |Â
Related post: Chrooted user does not start in his home directory and does not load his bash_profiles
â igal
Oct 19 '17 at 23:56
Related post: Chrooted user does not start in his home directory and does not load his bash_profiles
â igal
Oct 19 '17 at 23:56
Related post: Chrooted user does not start in his home directory and does not load his bash_profiles
â igal
Oct 19 '17 at 23:56
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
down vote
accepted
Looking up in /etc/passwd
is correct for local user accounts (unless the system administrator has gone out of their way to make things difficult). The correct general answer is to look up in the user database that contains the user account, e.g. LDAP. Most modern systems use NSS to list user databases, so check /etc/nsswitch.conf
on your system if you think there might be non-local accounts.
From an application's perspective, the correct answer is that the home directory is whatever the HOME
environment variable says.
Login programs (login
, sshd
, X display managers, etc.) normally set the HOME
environment variable to the home directory of the user that's logging in. âÂÂHigh-levelâ user change programs such as su
and sudo
change HOME
to (with sudo, it depends on the configuration and the command line options). So normally, the definition for âÂÂhome directory of the current userâ matches with the combination of âÂÂuser's home directoryâ and âÂÂcurrent userâÂÂ.
But chroot
doesn't change HOME
, so your session in the chroot inherits from the HOME
environment variable in the parent process, which is unsurprisingly /root
. In bash, like any other shell, ~
expands to the value of HOME
, defaulting to the user database lookup if HOME
is not set.
Solution: unset HOME
.
env -u HOME chroot --userspec=test path/to/subsystem/ /bin/bash
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
Looking up in /etc/passwd
is correct for local user accounts (unless the system administrator has gone out of their way to make things difficult). The correct general answer is to look up in the user database that contains the user account, e.g. LDAP. Most modern systems use NSS to list user databases, so check /etc/nsswitch.conf
on your system if you think there might be non-local accounts.
From an application's perspective, the correct answer is that the home directory is whatever the HOME
environment variable says.
Login programs (login
, sshd
, X display managers, etc.) normally set the HOME
environment variable to the home directory of the user that's logging in. âÂÂHigh-levelâ user change programs such as su
and sudo
change HOME
to (with sudo, it depends on the configuration and the command line options). So normally, the definition for âÂÂhome directory of the current userâ matches with the combination of âÂÂuser's home directoryâ and âÂÂcurrent userâÂÂ.
But chroot
doesn't change HOME
, so your session in the chroot inherits from the HOME
environment variable in the parent process, which is unsurprisingly /root
. In bash, like any other shell, ~
expands to the value of HOME
, defaulting to the user database lookup if HOME
is not set.
Solution: unset HOME
.
env -u HOME chroot --userspec=test path/to/subsystem/ /bin/bash
add a comment |Â
up vote
5
down vote
accepted
Looking up in /etc/passwd
is correct for local user accounts (unless the system administrator has gone out of their way to make things difficult). The correct general answer is to look up in the user database that contains the user account, e.g. LDAP. Most modern systems use NSS to list user databases, so check /etc/nsswitch.conf
on your system if you think there might be non-local accounts.
From an application's perspective, the correct answer is that the home directory is whatever the HOME
environment variable says.
Login programs (login
, sshd
, X display managers, etc.) normally set the HOME
environment variable to the home directory of the user that's logging in. âÂÂHigh-levelâ user change programs such as su
and sudo
change HOME
to (with sudo, it depends on the configuration and the command line options). So normally, the definition for âÂÂhome directory of the current userâ matches with the combination of âÂÂuser's home directoryâ and âÂÂcurrent userâÂÂ.
But chroot
doesn't change HOME
, so your session in the chroot inherits from the HOME
environment variable in the parent process, which is unsurprisingly /root
. In bash, like any other shell, ~
expands to the value of HOME
, defaulting to the user database lookup if HOME
is not set.
Solution: unset HOME
.
env -u HOME chroot --userspec=test path/to/subsystem/ /bin/bash
add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
Looking up in /etc/passwd
is correct for local user accounts (unless the system administrator has gone out of their way to make things difficult). The correct general answer is to look up in the user database that contains the user account, e.g. LDAP. Most modern systems use NSS to list user databases, so check /etc/nsswitch.conf
on your system if you think there might be non-local accounts.
From an application's perspective, the correct answer is that the home directory is whatever the HOME
environment variable says.
Login programs (login
, sshd
, X display managers, etc.) normally set the HOME
environment variable to the home directory of the user that's logging in. âÂÂHigh-levelâ user change programs such as su
and sudo
change HOME
to (with sudo, it depends on the configuration and the command line options). So normally, the definition for âÂÂhome directory of the current userâ matches with the combination of âÂÂuser's home directoryâ and âÂÂcurrent userâÂÂ.
But chroot
doesn't change HOME
, so your session in the chroot inherits from the HOME
environment variable in the parent process, which is unsurprisingly /root
. In bash, like any other shell, ~
expands to the value of HOME
, defaulting to the user database lookup if HOME
is not set.
Solution: unset HOME
.
env -u HOME chroot --userspec=test path/to/subsystem/ /bin/bash
Looking up in /etc/passwd
is correct for local user accounts (unless the system administrator has gone out of their way to make things difficult). The correct general answer is to look up in the user database that contains the user account, e.g. LDAP. Most modern systems use NSS to list user databases, so check /etc/nsswitch.conf
on your system if you think there might be non-local accounts.
From an application's perspective, the correct answer is that the home directory is whatever the HOME
environment variable says.
Login programs (login
, sshd
, X display managers, etc.) normally set the HOME
environment variable to the home directory of the user that's logging in. âÂÂHigh-levelâ user change programs such as su
and sudo
change HOME
to (with sudo, it depends on the configuration and the command line options). So normally, the definition for âÂÂhome directory of the current userâ matches with the combination of âÂÂuser's home directoryâ and âÂÂcurrent userâÂÂ.
But chroot
doesn't change HOME
, so your session in the chroot inherits from the HOME
environment variable in the parent process, which is unsurprisingly /root
. In bash, like any other shell, ~
expands to the value of HOME
, defaulting to the user database lookup if HOME
is not set.
Solution: unset HOME
.
env -u HOME chroot --userspec=test path/to/subsystem/ /bin/bash
answered Oct 19 '17 at 23:51
Gilles
508k12010031533
508k12010031533
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f399237%2fdetermining-home-dir-of-a-user%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Related post: Chrooted user does not start in his home directory and does not load his bash_profiles
â igal
Oct 19 '17 at 23:56