Bug 245236 - jexec: Ability to change the default shell
Summary: jexec: Ability to change the default shell
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-jail (Nobody)
URL:
Keywords: feature, needs-patch, needs-qa
Depends on:
Blocks:
 
Reported: 2020-04-01 13:39 UTC by Please
Modified: 2021-06-22 06:00 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Please 2020-04-01 13:39:21 UTC
I want to have different shells in different jails. It looks like there is a bug that prevents that. Unfortunately, this does not work:

#jexec 1 /usr/local/bin/bash
#echo $SHELL
/bin/csh

https://github.com/freebsd/freebsd/blob/master/usr.sbin/jexec/jexec.c#L132

For example, Midnight Commander has a build-in shell that relay on variable $SHELL. This means when you start mc (inside a jail) and then access shell it would be default one ( probably /bin/csh not one that was defined )

based on: https://pushpanel.io/2020/freebsd-12-1-change-the-default-shell-for-jexec/

Would you able to make relevant changes to set it up properly?
Comment 1 Dan Langille freebsd_committer 2021-06-22 01:33:55 UTC
Perhaps you are getting the bash shell:

$ sudo jexec 28 /usr/local/bin/bash
[root@test-nginx01:/] # echo $SHELL
/bin/csh


That is my bash prompt for the given shell.

Same jail:

$ bash
[dan@test-nginx01:~] $ echo $SHELL
/bin/sh

I get similar results on other jails & hosts:

[dan@slocum:~] $ echo $SHELL
/bin/sh
Comment 2 dewayne 2021-06-22 01:45:21 UTC
(In reply to Please from comment #0)
Perhaps changing the shell in /etc/master.passwd will solve the problem?

Running as root using csh. When I define two users bob uses /bin/sh, alice uses /bin/tcsh using vipw.
# jexec -U bob testjail
$ echo $SHELL
/bin/sh

# jexec -U alice testjail
> echo $SHELL
/bin/tcsh

# jexec -U bob testjail /bin/sh -c 'echo $SHELL'
/bin/sh
# jexec -U alice testjail /bin/sh -c 'echo $SHELL'
/bin/tcsh

which works nicely. 

However with
# jexec -U bob testjail echo $SHELL
/bin/csh
The SHELL variable has been evaluated before entering the jail, while
# jexec -U alice testjail sysctl kern.hostname
kern.hostname: testjail

With your example
#jexec 1 /usr/local/bin/bash
#echo $SHELL
/bin/csh
You're invoking the bash shell, which you are working in, within the jail, but examining the jailed user's SHELL variable, defined in passwd (or some dot file)

I hope this is helpful and I suspect does what is expected.