43

Say I've accidentally uninstalled every terminal emulator on my system: xterm, uxterm, gnome-terminal, guake, etc. Is there a way I can access bash without a terminal emulator?

One possible way I can think of would be to create and run a shell script, but that aside, can I get an interactive shell?

This is purely hypothetical, but thanks for all the answers!

4
  • 2
    There are programs which can run a shell, and provide some level of interactivity, by (partially) emulating a terminal, but aren't erminal emulators per se. GVim is one, for example.
    – muru
    Commented Jun 16, 2015 at 21:51
  • @muru so why you've not posted that as an answer yet ? :D Commented Jun 17, 2015 at 7:43
  • @Serg for the same reason I didn't post your IDE solution, or gedit's Python console - none of these are installed by default (though I think we can enable the gedit Python console without installing anything additional).
    – muru
    Commented Jun 17, 2015 at 7:50
  • @muru Ah, I see. Solutions that don't require any additional installation are always preffered . Definitely Commented Jun 17, 2015 at 7:52

7 Answers 7

65

Yes, by pressing CtrlAltF21. That gives you access to virtual console TTY2 . And you can reinstall any terminal emulator from there with sudo apt-get install terminal-name, where terminal-name is, gnome-terminal for example.

To get back to the GUI, first type exit to log out of the virtual console, then press CtrlAltF7 to switch back to the GUI. (In case you want to keep TTY session open, skip the typing exit part)

Edit: June 17,2015

I've thought up another solution: if you have any C language IDE, you could compile the following code, and the console of the IDE will now give you access to bash

#include<stdio.h>
#include <unistd.h>

void main()
{
        system("bash");
}

Note: CtrlAltF2 is not the only option. You can use CtrlAltF1, CtrlAltF3, CtrlAltF4, CtrlAltF5 and CtrlAltF6 too, which will give you virtual console TTY1, TTY3, TTY4, TTY5 or TTY6 respectively.

10
  • 1
    @ThomasW. I know, but on some systems like Fedora tty1 isn't there, so I got into habbit of saying F2 Commented Jun 15, 2015 at 12:11
  • 19
    @Huey this is accessible on all systems , failsafe, unless you've manually disabled ttys, and is basically how linux/unix is by default - text console. GUI is really optional on *nix systems Commented Jun 15, 2015 at 12:12
  • 8
    @Huey The virtual console is what Linux was build to do in the first place. Everything else is a feature which was added later. And it is just a too useful feature that it would make sense to remove it again.
    – kasperd
    Commented Jun 15, 2015 at 17:02
  • 11
    Once upon a time, you'd normally log in via the text console and then run xinit or startx to actually get into X11, if you needed to run a GUI program for some reason. :)
    – fluffy
    Commented Jun 16, 2015 at 7:52
  • 1
    I've throught up another solution. See my edit, guys Commented Jun 17, 2015 at 7:42
30

If you have an ssh server running, than you can connect via ssh from another system.

ssh <your_remote_user_name>@<your_remote_host>

If I install a system, then I first install and start the SSH server. A kind of life insurance. =)

0
24

Ctrl+Alt+(F1 through F4 at least, maybe up to F6) run a terminal interface on the virtual consoles. Once there, to get back to the GUI, use Ctrl+Alt+F7.

If you do any of those, you should be able to get to a terminal you can login to and then access the terminal. Bash scripts will, however, continue to run, if they're automated scripts dropped into cron and such or double clicked to run (but not in terminal). The terminal emulators which 'give you' an interactive shell, but ultimately bash, zsh, etc. which are the actual shells still exist and can run either via cron, scripts, and even the virtual consoles on the keyboard combos above.

Note though that if your scripts need the interactive interface, you'll have to use the virtual consoles, or install an emulator again.

1
  • 2
    F1 through F6 on my computer.
    – Scimonster
    Commented Jun 15, 2015 at 13:54
13

If this is a question from a test, for completeness i'd add normal serial tty's, where you'd connect to your computer with a serial cable. you'd need a getty (or whatever tty serial listeners are called now) previously configured before you lost your terminal tho, and you'd need a second computer to talk to the first, so as a home emergency this is not likely to happen.

You may also have some webmin console that gives you (in effect) shell access, though not techncally interactive shell. at that point you're better off doing easy commands, like apt-get some-terminal-emulator.

If you have a browser window open, you could in theory search for a java terminal emulator but my guess is that you'd have to install ahead of time, and just having a browser window wouldn't let you access the underlying pty's right, but I have no time to test either way.

so, the above are "what are all the possible ways" questions, not necessarily useful in real life for home, though most server rooms would probably have serial access.

hmm, a lot of other tools (emacs, vim, etc) allow some level of shelling out. lets hope you have xemacs open

1
  • +1 for the record in emacs you can use M-x shell; in gvim there is ESC :shell; while geany has a "virtual terminal emulator widget (VTE)" in a tab of the message pane provided that libvte.so is available Commented Jun 16, 2015 at 18:42
6

Although all answers above is perfect, and since you are using Linux, then you have many other possible solutions:

  • Virtual ttys as described in @serg answer which is the perfect solution
  • SSH as described in @A.B solution which is lovely trick, but you have to take in consideration to have openssh server running.
  • Another possible solutions(it's not the perfect but just to show other possibilities): LiveCD , Recovery Mode
7
  • 3
    Overkill solution.
    – Thomas Ward
    Commented Jun 15, 2015 at 15:24
  • @ThomasW. Why!? It's just another option? Why you considered it overkill solution?!
    – Maythux
    Commented Jun 15, 2015 at 15:25
  • 2
    @Maythux while technically correct, it's indeed a bit overkill , when we already have TTYs available and ssh. LiveCD solution is more applicable when you've installed coreutils (yes, I've done that before by accident) or something really got messed up. Commented Jun 15, 2015 at 15:28
  • 1
    @Serg but it still a case, plus It's just another solution, I said in addition to using tty as you described he has an option of liveCd, also he has option of recovery mode... WE are talking about linux, many solutions for same problem. I don't think recommending a liveCd is a problem!
    – Maythux
    Commented Jun 15, 2015 at 15:30
  • 1
    @Maythux If they are already able to login and have the 'virtual consoles' on TTYs, it's overkill and extra work to just boot up into a LiveUSB/LiveCD to do it. Especially since it's not a case of "I Can't Access Anything" so no need for the big guns (as Serg alluded to in comments)
    – Thomas Ward
    Commented Jun 15, 2015 at 16:49
2

So I am going to be pedantic here:

Is there a way I can access bash without a terminal emulator?

Sure any script that begins with #!/bin/bash will do that.

Is there a way I can get a bash prompt without a terminal emulator?

Continuing with my theme of being pedantic, lets poke some holes in some of the other answers.

Say I've accidentally uninstalled every terminal emulator on my system:

This is actually very hard to pull off because

by pressing CtrlAltF2

you switch to another virtual console which has the linux kernel virtual terminal emulator running on it, which is very hard to remove and requires recompiling the kernel with nonstandard options. So lets blow holes in the ssh/telnet/serial-port options, those require a remote terminal emulator; as for webmin, it also has a terminal emulator (just a lousy one).

There is only one way to use the function of a terminal without a terminal emulator: use a real terminal. I used to have a Televideo and a teletype (not a TeleType, this was a knockoff) I was able to edit files with both (vi on the Televideo, ed on the teletype (what a pain in the rear)) make calls out to a local bbs using minicom and seyon from the televideo. You know the only thing I miss about them is the bragging rights, but I picked up a couple configuration terminals for industrial printers that have a two line 20 column display, a keyboard and a rs232 interface that will work for emergency configuration repair once I figure out where my ed manual is.

0

Similar to @A.B.'s answer, if you have a web server running (I believe stanard Ubuntu comes with apache), you could run a shell in your own browser with something like phpshell.

Personally, I'd just fire up emacs and M-x shell RETURN.

2
  • Standard Ubuntu doesn't come with a web server.
    – muru
    Commented Jun 17, 2015 at 8:59
  • 2
    @muru It comes with a web server in the repository. Just open a terminal and type sudo apt-get install apache. Oh, wait.
    – Mr Lister
    Commented Jun 19, 2015 at 7:27

You must log in to answer this question.

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