Is there a config file that stores the default shell (bash, zsh, etc) for the current user ?
Asked
Active
Viewed 2,337 times
1 Answers
5
The default shell used by a user is contained in the seventh field of /etc/passwd or its equivalent.
$ getent passwd xxxxxx | awk -F: '{ print $7 }'
/bin/bash
Ignacio Vazquez-Abrams
- 111,361
- 10
- 201
- 247
-
Is there another way that doesn't require access to such file like passwd – faressoft Jul 30 '18 at 17:44
-
The *only* reliable place this information can be found is `passwd`. – Ignacio Vazquez-Abrams Jul 30 '18 at 17:45
-
-
1
-
-
-
1@faressoft: You can check that with `strace`, for example `strace chsh -s $(command -v bash) |& grep open` – Arkadiusz Drabczyk Jul 30 '18 at 18:31
-
@faressoft Please note you should always have access to `/etc/passwd`. It is where you user ID and username are mapped, and your home directory, and default shell, and it has to be accessible by a lot of things. You are maybe thinking of `/etc/shadow` (which is where passwords are stored) and that is usually not world-readable. – BenjiWiebe Jul 30 '18 at 19:24
-
@faressoft In fact, when you log in, the shell you get actually *is* read from your `/etc/passwd`, via the same mechanism getent uses. – BenjiWiebe Jul 30 '18 at 19:26