# chsh not working?



## moskito (Oct 18, 2019)

I'm trying to change my default shell from bash to zsh but its failing:

```
$ chsh -s /usr/local/bin/zsh
Password:
chsh: entry inconsistent
chsh: pw_copy: Invalid argument
```

The same happens with the other shells: /bin/tcsh, /usr/local/bin/bash.
Any hint on what's going on?


----------



## SirDice (Oct 18, 2019)

It looks like your user's entry is not correct and it's causing this error. What does `getent passwd <username>` return?


----------



## moskito (Oct 18, 2019)

Running `getent passwd myuser` seems ok, it returns:

```
myuser:*:1001:1001:My Name:/home/myuser:/usr/local/bin/bash
```
(replaced my username and real name)


----------



## gpw928 (Oct 19, 2019)

It's still smelling like an inconsistency in one of these files:
	
	



```
-rw-r--r--  1 root  wheel    634 Sep  5 16:31 /etc/group
-rw-------  1 root  wheel   2706 Sep  5 16:31 /etc/master.passwd
-rw-r--r--  1 root  wheel   2310 Sep  5 16:31 /etc/passwd
-rw-r--r--  1 root  wheel  40960 Sep  5 16:31 /etc/pwd.db
-rw-r--r--  1 root  wheel    361 Oct 18 10:51 /etc/shells
-rw-------  1 root  wheel  40960 Sep  5 16:31 /etc/spwd.db
```
Do the password files (passwd and master.passwd) have the same number of lines?  Are they the same except for the password field, and the extra fields like "::0:0" in front of your name?

Where "^V^M" means type Ctrl-V and then Ctrl-M, do you get any output from:
	
	



```
grep "^V^M" /etc/group /etc/passwd /etc/shells && echo bother
```

Can you add a new user, with `adduser(8)`?

Can you then change the shell for that user?


----------



## T-Daemon (Oct 19, 2019)

pwd_mkdb(8), run
`pwd_mkdb -C /etc/passwd`
and
`pwd_mkdb -C /etc/master.passwd`

What do you get if you execute `chsh` alone, without any options?

You can also set the new user shell manually with vipw(8), but the entry inconsistent error should be investigated. Had you maybe hard resetted the system some time before?


----------



## moskito (Oct 19, 2019)

I now copied the passwd, master.passwd, pwd.db and spwd.db files from an older zfs snapshot, then run `chpass -s /bin/sh myuser`.
Got the message `chpass: user information updated` but it isn't. 
`vipw` shows the new `/bin/sh`, but `chsh` alone shows the older `/usr/local/bin/bash`. New logins still go to the older one.

Running `pwd_mkdb -C /etc/passwd` gives


```
pwd_mkdb: corrupted entry
pwd_mkdb: at line #3
pwd_mkdb: /etc/passwd: Inappropriate file type or format
```

and line 3 is the root and contains `root:*:0:0:Charlie &:/root:/bin/csh`.
I also noticed that the next line has no shell defined: `toor:*:0:0:Bourne-again Superuser:/root:`.

Followed the suggestions above by *gpw928 *and found that `adduser` also fails, the other things were ok.


----------



## gpw928 (Oct 19, 2019)

While trouble-shooting, you should establish a root login, in a separate window, in case you need to use it to recover.
The missing shell defaults to `/bin/sh`.  It's normal for the "toor" account (Bourne shell for root), and is not an issue.
Above, you are only looking at /etc/passwd.  You need to have a look at /etc/master.passwd as well, and tell us what you see, especially around line 3 (usually the entry for root).
To examine and re-generate the password files:
	
	



```
sudo cp -p /etc/master.passwd /etc/master.passwd.save
sudo vipw
:set list
```
The ":set list" will make non-printable characters visible, and place a dollar sign at the end of each line (indicating the presence of the newline character).
Double check the syntax and content of line 3.
Any appearance of caret "^" indicates a problem character follows.  If you see that, fix it.
Make sure that the shell for your account is what you want, and that its full path name appears in /etc/shells.  
Then make a trivial change, like adding a space to a comment in line 1 or 2, and "wq!"
Your password files should all be re-generated.


----------



## moskito (Oct 20, 2019)

Ok, it's finally fixed. I have no idea what was causing the problem, but it started working with `vipw` and  then added a space in the comment line 2...
Thanks a lot gpw928 for your suggestions!


----------



## weberjn (Jan 23, 2021)

If google led you to this thread:

see:









						Solved - pwd_mkdb: /etc/passwd: Inappropriate file type or format
					

This is on a fresh 11.4 system, updated to p1 using freebsd-update.  doas pwd_mkdb -C /etc/passwd pwd_mkdb: corrupted entry pwd_mkdb: at line #3 pwd_mkdb: /etc/passwd: Inappropriate file type or format  I didn't messed with it at all. How could it be corrupted?  p/s: Please run the command above...




					forums.freebsd.org


----------

