1

I read the answers on those questions (this && this), neither of them work for me!

% uname --operating-system --kernel-name --kernel-version --kernel-release 
Linux 4.9.6-200.fc25.x86_64 #1 SMP Thu Jan 26 10:17:45 UTC 2017 GNU/Linux

I download/install st terminal (simple terminal), and I would like to set it as my main terminal-emulator, but I did a huge mistake, which is running this command as root: % su -c 'chsh -s /usr/local/bin/st'.

Now, whenever I want to login/run a command as root, a message is printed: Can't open display. I tried the following commands (as shown below), but non of them work..

% env -i bash
% su
Password:
Can't open display
% su -c 'env -i bash'
Password:
Can't open display
% su -c 'chsh -s /usr/bin/bash'
Password:
Can't open display
% su -s bash
Password: 
su: using restricted shell /usr/local/bin/st
Can't open display
% su
Password:
Couldn't read from shell: Input/output error
child finished with error '256'
% 

UPDATE: I tried to do as explained in the proposed answer

  1. From the bootloader prompt, navigate to the regular entry you boot from.
  2. Instead of pressing Enter press e to first edit the kernel command line parameters
  3. In the editor that opens, use the arrow keys to find the line that starts with linux, go to its end and append init=/bin/sh to it. This will replace your init system temporarily by your system's shell and since init is started by root, this will be a root shell.
  4. Press CTRL+X to boot the modified entry
  5. run chsh again with the correct parameters

But when I did the step 4, I was faced with this screen!

0x0584
  • 1,284
  • 2
  • 15
  • 23
  • Well, changing root's shell is in itself not quite what one wants to do. Are you able to `su root -c /bin/bash`? (insert correct full path to `bash`) – Kusalananda Feb 03 '17 at 13:10
  • Failing that, boot into single-user mode and change the shell from there. – Kusalananda Feb 03 '17 at 13:13
  • 1
    @kusalananda `-c /bin/bash` are arguments passed to the target user's login shell (here `st`). – Stéphane Chazelas Feb 03 '17 at 13:15
  • Single-user boot it is then. – Kusalananda Feb 03 '17 at 13:19
  • @StéphaneChazelas so, what's the solution? – 0x0584 Feb 03 '17 at 13:36
  • @Kusalananda I receive the same output: `Couldn't read from shell: Input/output error \n child finished with error '256'` – 0x0584 Feb 03 '17 at 13:37
  • What's the Unix you're using, Linux? What distribution? – Kusalananda Feb 03 '17 at 13:39
  • Even if could run su from an X11 session after having allowed root to connect to it, `st` would invoke root's login shell so would start itself indefinitely. You'd need another way to run commands as root like with sudo if configured or use whatever recovery boot option is available on your system to fix the user account database. – Stéphane Chazelas Feb 03 '17 at 13:43
  • @Kusalananda fedora 25, where did fedora store shell variables for the `root`? can I login using a live DVD and delete a file or so? I search but I did not find anything! – 0x0584 Feb 03 '17 at 18:48
  • Boot into a root shell as described in the duplicate question. Then run `chsh` again with the correct parameters. – Gilles 'SO- stop being evil' Feb 03 '17 at 19:35
  • @Gilles I did as you said but nothing happens, I was faced with a (end Kenerl panic - not syncing: VFS: Unable to mount .... ) – 0x0584 Feb 04 '17 at 17:09

1 Answers1

0

I did a huge mistake

You did indeed. The way to recover from this is to find a way to run a command as the superuser but without using the superuser's configured login shell.

Rescue and emergency modes won't achieve this, unless you are lucky enough to have /usr on a separate disc volume — ironically the opposite of the trend of the past 30 years. If the disc volume containing /usr/local/bin/st is not the root, the file will not be executable. In such a situation emergency login with the likes of sulogin or emergency-login will attempt to fall back to a hardwired shell name.

Another way to achieve this is with the -s option to sudo, which runs the shell given by the SHELL environment variable as the interactive shell, rather than the shell given in the user account database for the superuser. (Contrast the -i option.)

doas -s similarly employs the shell specified by the SHELL environment variable.

Some operating systems' su commands can also do this, with a --shell option. This is not universal, though. Moreover it is ignored, as you have encountered, if the superuser's shell in the account database is not in the authorized shells list (/etc/shells).

JdeBP
  • 66,967
  • 12
  • 159
  • 343