1

I have made an interactive shell for my Linux, and has chsh-ed to it to test it. However, it has a bug and I am now unable to get back to my bash/sh. I am not able to type in any command or perform any action to my machine.

I'm using Ubuntu 20.04.

I have tried to ssh into the machine with a parameter that tells it to run sh/bash, but it didn't seem to work and falls back to the shell that I have made.

This is what I have tried:

ssh username@hostname -p 2222 bash
ssh username@hostname -p 2222 -t bash

My root account has no password and therefore is not activated (I think) and I do not have another user account to do the chsh for me.

How do I force my machine to use Sh or Bash on a tty so that I can fix my shell and use my machine?

Or just any way to get me out from my shell other then reinstalling my computer?

1
  • Try to boot from a bootable livecd, mount your hard drive, fix the login shell.. And once you reboot and get back in, follow the advice screamed around the world, "CREATE AN ALTERNATE LOGIN ACCOUNT FOR SAFETY!"
    – C. M.
    Commented Jun 19, 2021 at 19:03

2 Answers 2

1

It's unlikely that you will be able to solve this via SSH for the reasons discussed here

However you certainly shouldn't need to resort to reinstalling, if you have physical access to the machine.

First, try pausing the boot and edit the grub command line to set rw init=/bin/sh or rw init=/bin/bash. Then edit the /etc/passwd file using vipw to change your login shell to something sensible. See

If that's not possible then you can always use a live recovery CD/DVD/USB from which you can mount the old root partition and edit its /etc/passwd (or chroot to the old system and use chsh - but that's more complicated).

0

If you can log in as root (locally or remotely), you can use chsh(1) to change the login shell (or use vipw(1) to edit /etc/passwd and friends, or edit the files directly).

Be careful. Don't trust random dudes on the 'net, read and understand the commands you are executing.

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .