Set zsh as default shell

I'm just getting started with coder.com - another team at my company set up an instance. I tried using chsh to switch my default shell to zsh, but new vscode sessions are still using bash. Restarting the workspace reset the shell to bash again. What's the recommended way to get my shell to zsh by default? Will I need to build my own workspace AMI or something? Thanks in advance!
7 Replies
Codercord
Codercord2w ago
<#1303147690338684978>
Category
Help needed
Product
Coder OSS (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
Atif
Atif2w ago
You should ask your template admin to add dotfiles modules to the template, and then you can use your dotfiles to customize to your environment. https://registry.coder.com/modules/dotfiles
Dotfiles - Coder Registry
Allow developers to optionally bring their own dotfiles repository to customize their shell and IDE settings!
dataike
dataikeOP2w ago
Thanks! that's supported, but I'm not clear on what I'd put into a dotfiles repo to make zsh the default. I was planning on chsh, but seems like that doesn't work. Do you know of any example repo that switches the default shell?
Phorcys
Phorcys2w ago
yes, you'd use chsh here's a script I wrote to change the shell using chsh
#!/usr/bin/env zsh

if [ "$USER" != "root" ]; then
exit 1
fi

CHSH_COMMAND="chsh"
CHSH_ARGS=("-s" "${2:-$(which zsh)}" "${1:-$USER}")
CHSH_PAM="/etc/pam.d/chsh"

CHSH_EXIT=2

if grep -q required $CHSH_PAM; then
echo "[+] Changing PAM policy for chsh"
sed s/required/sufficient/g -i /etc/pam.d/chsh

echo "[+] Setting default shell"
$CHSH_COMMAND ${CHSH_ARGS[@]}
CHSH_EXIT=$?

echo "[+] Reverting PAM policy for chsh"
sed s/sufficient/required/g -i /etc/pam.d/chsh
else
$CHSH_COMMAND ${CHSH_ARGS[@]}
CHSH_EXIT=$?
fi

exit $CHSH_EXIT
#!/usr/bin/env zsh

if [ "$USER" != "root" ]; then
exit 1
fi

CHSH_COMMAND="chsh"
CHSH_ARGS=("-s" "${2:-$(which zsh)}" "${1:-$USER}")
CHSH_PAM="/etc/pam.d/chsh"

CHSH_EXIT=2

if grep -q required $CHSH_PAM; then
echo "[+] Changing PAM policy for chsh"
sed s/required/sufficient/g -i /etc/pam.d/chsh

echo "[+] Setting default shell"
$CHSH_COMMAND ${CHSH_ARGS[@]}
CHSH_EXIT=$?

echo "[+] Reverting PAM policy for chsh"
sed s/sufficient/required/g -i /etc/pam.d/chsh
else
$CHSH_COMMAND ${CHSH_ARGS[@]}
CHSH_EXIT=$?
fi

exit $CHSH_EXIT
you run it as root as ./changeshell.sh <user> <shell> I can make a Coder module to switch the shell if you want
dataike
dataikeOP2w ago
thanks Theo! I'll give it a try.
Phorcys
Phorcys2w ago
let me know how it goes!
dataike
dataikeOP2w ago
I tried this today, but it looks like our installation runs dotfiles/install.sh as coder not root (so the above just exits 1). So I tried switching the script to just sudo chsh -s /usr/bin/zsh coder which runs, but the shell I get after connecting is still bash. I'll follow up with the folks that set up our installation to see if they have ideas
Want results from more Discord servers?
Add your server