# Setting up TCSH



## MaxRuse11 (Jan 16, 2018)

I've got a Digital Ocean droplet running FreeBSD which I shell into.

I can locate tcsh under /bin/tcsh but using setenv in my local .cshrc file doesn't cause this shell to be used on next login.

Env reports the shell as sh and the prompt hasn't changed to >

Editing master.passwd to use tcsh doesn't change to tcsh on next login

where do I need to edit to move to Tcsh?


----------



## swegen (Jan 16, 2018)

`pw usermod <username> -s /bin/tcsh`


----------



## ralphbsz (Jan 17, 2018)

Your login shell is stored in /etc/passwd.  There are many tools that can be used to modify it.  I personally like `vipw`, which edits that file directly.  Swegen above likes `pw`, another fine choice.  It will be instructive to read that file, while looking at the documentation in passwd(5).


----------



## ShelLuser (Jan 17, 2018)

The best way to do this is using `chsh` which is short for "Change Shell" and an alias for chpass(1): adds or changes user database information.

The reason why I consider this command to be the best option is because you don't have to be root to use this. Better yet: there can be absolutely no doubt what you need to change either, something which doesn't necessarily apply if you edit /etc/passwd directly:


```
#Changing user information for peter.
Shell: /usr/local/bin/ksh
Full Name: Peter <bleep>
Office Location: xx
Office Phone: xx
Home Phone: xx
Other information:
```
So in your case all you'd have to do is know where csh is located (probably /usr/csh or /bin/tcsh) and then change this accordingly.


----------



## Sensucht94 (Jan 17, 2018)

Why not just?:

```
chsh -s tcsh <username>
```
Like in any Unix-like system, including OS X, any *BSD, and GNU/Linux

see chpass(1), as well as *chsh* on wikipedia


----------



## MaxRuse11 (Jan 17, 2018)

```
$ sudo pw usermod freebsd -s /bin/tcsh
pw: entry inconsistent
pw: pw_copy(): Invalid argument
$ sudo chsh -s tcsh freebsd
chsh: entry inconsistent
chsh: pw_copy: Invalid argument
```


----------



## SirDice (Jan 17, 2018)

You've edited master.passwd by hand and made a mistake in there. Never, ever, edit that file by hand.


----------



## MaxRuse11 (Jan 17, 2018)

and, after editing as sudo when I :

```
tail /etc/passwd


freebsd:*:1001:1001:FreeBSD:/usr/home/freebsd:/bin/tcsh
```


----------



## MaxRuse11 (Jan 17, 2018)

SirDice said:


> You've edited master.passwd by hand and made a mistake in there. Never, ever, edit that file by hand.



I don't see any edits in there:

```
# $FreeBSD: releng/11.1/usr.sbin/pw/tests/master.passwd 272445 2014-10-02 19:53:
37Z brd $
#
root:*:0:0::0:0:Charlie &:/root:/bin/csh
toor:*:0:0::0:0:Bourne-again Superuser:/root:
```


----------



## SirDice (Jan 17, 2018)

Well, you did something to it, because it's out of sync with /etc/passwd. The passwd file still has the freebsd user and master.passwd doesn't.


```
# $FreeBSD: releng/11.1/usr.sbin/pw/tests/master.passwd 272445 2014-10-02 19:53:
37Z brd $
```
This might be due to a copy/paste error but this should all be on one line.

I would try to delete the account: `pw userdel freebsd` and recreate it using the same UID/GID.


----------



## MaxRuse11 (Jan 17, 2018)

SirDice said:


> Well, you did something to it, because it's out of sync with /etc/passwd. The passwd file still has the freebsd user and master.passwd doesn't.
> 
> 
> ```
> ...



EDIT - I am not sure that I have edited that file. I've just checked the stamps on that directory:

```
$ ls -l /usr/src/usr.sbin/pw/tests/
total 92
-rw-r--r--  1 root  wheel   1758 Jul 20 23:42 crypt.c
-rw-r--r--  1 root  wheel     99 Jul 20 23:42 group
-rwxr-xr-x  1 root  wheel    992 Jul 20 23:42 helper_functions.shin
-rw-r--r--  1 root  wheel    640 Jul 20 23:42 Makefile
-rw-r--r--  1 root  wheel    261 Jul 20 23:42 Makefile.depend
-rw-r--r--  1 root  wheel    179 Jul 20 23:42 master.passwd
```
- all same date

I'm not sure that deleting the user isn't a possibility as they are setup by digital ocean as a default - authentication for these accounts is via an agreed ssh.

I could modify the etc/passwd back to csh - which is the change I've made?


----------



## SirDice (Jan 17, 2018)

That's the _source_ of the files, not the actual files. These get installed during a `make installworld` and mergemaster(8). They are not the "real" files the OS actually uses.


----------



## sko (Jan 17, 2018)

If you edited /etc/master.passwd by hand (which you should NEVER do as already said), you'd have to manually update the passwd-db file which is the actual file that is used.
The db can be updated with pwd_mkdb(8): `pwd_mkdb -p /etc/master.passwd`

But as said: never edit any of the /etc/[master.]passwd files by hand unless absolutely necessary. Either use the vipw(8) tool if you _really_ want to edit the file by hand (and possibly introducing errors) or use the chsh(8) tool. Both are available on all BSDs and a varying subsets of other UNIX-derived systems and some Linux variants. On Solaris/illumos you can use `passwd -e` (IIRC most Linux systems also have this option for passwd).


----------



## MaxRuse11 (Jan 17, 2018)

SirDice said:


> That's the _source_ of the files, not the actual files. These get installed during a `make installworld` and mergemaster(8). They are not the "real" files the OS actually uses.



Okay, but as this system is from an image (presumably, from the Digital Ocean droplet) and I didn't run either of those commands - can I restore without removing the user?


----------



## SirDice (Jan 17, 2018)

I would take a long hard look at /etc/master.passwd, you most likely introduced an error there when you first edited it.


----------



## MaxRuse11 (Jan 17, 2018)

I checked the date -r for the edit, and it was edited, but there wasn't any entry for my user.
Ran `pwd_mkdb -p /etc/master.passwd`
used `pw usermod name -s /bin/tcsh`

got tcsh. 

Thanks all


----------



## Deleted member 30996 (Jan 17, 2018)

MaxRuse11 said:


> toor:*:0:0::0:0:Bourne-again Superuser:/root:



If it was me, the first thing I would do after getting these password issues ironed out would be to delete toor from /etc/passwd and reboot.



ralphbsz said:


> Your login shell is stored in /etc/passwd.  There are many tools that can be used to modify it.  I personally like `vipw`, which edits that file directly.  Swegen above likes `pw`, another fine choice.  It will be instructive to read that file, while looking at the documentation in passwd(5).



I use editors/leafpad to delete toor from /etc/passwd as one of the first things I do after rebuilding my system and have never had a problem with it.

I never edit master.passwd.


----------



## SirDice (Jan 17, 2018)

Good. The pwd_mkdb(8) probably fixed the 'inconsistent' error messages you had. Added bonus, you learned a bunch of new commands during this exercise


----------



## SirDice (Jan 17, 2018)

Trihexagonal said:


> I use editors/leafpad to delete toor from /etc/passwd as one of the first things I do after rebuilding my system and have never had a problem with it.


The /etc/passwd file is generated from master.passwd. Any time pwd_mkdb(8) is run that user will re-appear in passwd again. The passwd file itself is actually rarely used, it's mainly there for compatibility reasons. The user would still be in /etc/spwd.db and /etc/pwd.db (the actual user databases) and would still exist. Use `pw userdel toor` instead, that will remove the account from everything.


----------



## Deleted member 30996 (Jan 17, 2018)

SirDice said:


> The /etc/passwd file is generated from master.passwd. Any time pwd_mkdb(8) is run that user will re-appear in passwd again.



That would explain it having reappeared at times after I'd deleted it.


----------



## poorandunlucky (Jan 19, 2018)

You really should use `vipw` to edit the password files by hand...

You should really learn vi, if you don't already know it, too... so...


----------



## Deleted member 30996 (Jan 20, 2018)

I can use editors/vim, poorandunlucky, but I'm a lot quicker with editors/leafpad. It works just as well for me and is what I've always used to edit files.

I don't have anything but editors/vi, editors/vim or editors/leafpad (except EE which I Iove) on any of my machines and have no use for anything but a text editor. 

I could edit everything from the login terminal using `ee` and be more comfortable than with editors/vim as far as that goes.


And for the record, I watch files like /etc/passwd and is how I knew the toor line had reappeared.


----------



## max21 (Jan 22, 2018)

This probably won't help you but this is what I use to do to make bash the default shell.  Since tcsh is in /bin/tcsh... I just tried it to and it works.

Make tcsh(1) default shell:

```
chsh -s  /bin/tcsh
echo "/bin/tcsh" >> /etc/shells
chsh -s  /bin/tcsh
```


----------



## SirDice (Jan 22, 2018)

You don't need to add it to /etc/shells, it's already there by default.


----------

