[KDE] Make Konsole respect /etc/passwd

Difficulty: ⯪☆☆☆☆


Konsole is a pretty sweet package, compared to other solutions provided by other desktops. But one point of contention may be the need to always define what shell you want to use per-profile. While Konsole not respecting what’s in /etc/passwd save for fallback could be considered a good thing, what if you want to use Konsole’s fallback anyway, without being nagged about the current profile’s Command field being empty?

Thanks to DrBaco’s solution for this problem on Stack Exchange, we can do that. Following their instructions, a script can be made so when used as Command, the shell used as fallback in /etc/passwd when it is malformed can be used anyway, without the warning of an empty / malformed Command string.


Outdated solution, preserved for historical reference. ### Script To create the script, do the following:

:heavy_dollar_sign: In konsole or preferred terminal emulator

sudo nano --backup /usr/local/bin/shell.sh

:mag_right: shell.sh can be anything, but keeping it vaguely descriptive so you know what you’re looking at is best.
:spiral_notepad: If you would rather use a graphical editor such as kate then open normally and kate will prompt for authentication prior to saving.

Then copy (Ctrl+C) this:
:clipboard: Content which will become shell.sh

PSHELL=$(getent passwd $USER|cut -d: -f7)
eval "$PSHELL"

And paste into nano (Ctrl+Shift+V) the new clipboard contents.

Save in nano (Ctrl+O) and exit (Ctrl+X).


With control of the terminal returned and ready to execute a new task, perform the following:

:heavy_dollar_sign: Trust and execution of shell.sh

sudo chmod +x /usr/local/bin/shell.sh`

:fast_forward: Likely execution is not necessary, and was included by DrBaco as a sanity check. If no errors, script functioned.

:telescope: You can also place echo lines, output neofetch if you have that installed, run custom commands, basically whatever you want in shell.sh but that’s not within this writ’s scope, and should be limited to your shell’s RC file where applicable.

Then in konsole define for current and future profiles /usr/local/bin/shell.sh so the next time it executes, it uses the shell defined in /etc/passwd which you can change using chsh -s, which matches the bahaviour one would expect when using any of the various TTYs available to them, or when using xterm / uxterm.


Here is the breakdown of what the script does, per-line:
1: Crunchbang: typical boilerplate stuff to include in a script which defines what shell executes to perform tasks assigned thereafter
2: Assign to variable $PSHELL the output of (entry for active $USER in database /etc/passwd piped to cut, de-limited to colon, showing only the seventh field)
3: Execute $PSHELL

Since konsole executes the script as a command, whatever is in it, is executed prior to permitting control of the shell.


This may be a security risk depending on where you end up placing this script, if not within the path used above so if modifying what is provided for your environment, please be conscious of any security concerns your decisions may cause, and consult your senior administrator when applicable for addressing any concerns which may be present in the establishment your system instance resides.

Turns out, unlike what is hidden in the expandable above, @papajoke made a fool of me by providing an even better Command solution. Simply open Konsole and define your Command string as $SHELL (case-sensitive).

That’s it. Quick, easy and painless. Anybody can do it, which upgrades the ease of use from one star to basically nothing.


Using what is defined for $PSHELL by itself causes Konsole to crash, but using $SHELL worked. So I will revise my OP to omit the original solution in favour of using $SHELL.