Switching to command line in linux

How do I switch between GUI and command line startup?

I’m not sure what I did, but my computer now starts to a command line interface, rather than a GUI. How do I switch between GUI and command line startup?

Could you please edit your question to include the content of /etc/default/grub or specifically the values of GRUB_CMDLINE_LINUX_DEFAULT and GRUB_CMDLINE_LINUX ? See “How do I get information from the logs on my computer when I only have access to the command line?” if you need help with that. Thanks.

3 Answers 3

  1. Open a text-only virtual console by using the keyboard shortcut Ctrl + Alt + F3 (or Ctrl+Alt+ F3 — F6 ).
  2. At the login: prompt type your username and press Enter .
  3. At the Password: prompt type your user password and press Enter .
  4. Now you are logged in to a virtual console, and you can run terminal commands from the console. For example, you can run terminal commands from the virtual console to repair your boot problem, but Ubuntu Server boots to a virtual console by default. To bring up the normal Ubuntu login screen run this command:
 sudo systemctl start lightdm.service 
 sudo systemctl start graphical.target 

There is something not running properly that avoid the desktop to start properly, but first try this:

press Alt + F7 (or repeatedly Alt + Right ) and you will get back to the GUI session.

if it does not work, in the command line type

I tried this solution and it worked:

sudo rm -Rf /var/lib/dpkg/lock sudo apt dist-upgrade -y sudo apt update 

You must log in to answer this question.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.17.43537

Ubuntu and the circle of friends logo are trade marks of Canonical Limited and are used under licence.

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

How to Switch Between CLI and GUI on Linux Server

If we trace the evolution of computers, we can see that initially, we don’t have Mouse. So, we used to interact with computers having Command Line Interface (CLI) only through keyboards passing inputs to perform actions via command line program.

Читайте также:  Linux uml user mode linux

As progressed, now we can easily interact and perform actions via a graphical user interface (GUI) that provides various menus like windows, and buttons. Nowadays people are more inclined and used to GUI-based OS.

Altogether, the computer now comes with an option to work either in the command line or graphical mode. Further, you can also start GUI from the command line and CLI from graphical mode, whichever suits your requirement.

In this article, we’ll see how can we switch between the command line and the graphical interface on Linux Server. But before that, let’s also get an overview of the concept that actually makes changing GUI to CLI and CLI to GUI work.

Init-based Run Levels in Linux

In Linux with an init system manager, the run level defines the operating state of the init process and the whole system and indicates system services that are running.

When the Linux Kernel boots, the init process is the first thing that gets started, and further, it leads to the initialization of other Linux processes.

The moment the init process begins it looks for the value of the default run level of the system. Run level i.e. state of the system is represented in a single-digit integer.

The Standard Linux kernel supports the following seven different run levels:

  • 0 – Halt the system
  • 1 – Single user mode
  • 2 – Multiple user mode with no network file system
  • 3 – Multiple user mode under CLI
  • 4 – User-definable
  • 5 – Multiple user mode under GUI
  • 6 – Reboot

By default, if a system has a desktop environment like GNOME or KDE, it boots to graphical run level 5, or else the command line run level 3.

That is why by simply changing the run level of the system you can switch between user interfaces.

Change Init-Based Run Levels in Linux

If you want to know the current run level of your system it is running, type:

Check Linux Run Level

To switch to CLI from GUI, change the run level to 3 by running:

Enter and password and you’ll be redirected to the command line mode where you need to log in again.

Likewise, if you want to come back to GUI from CLI, type the following in the command line:

Set A Default Init Run Level

Want to boot your system directly to the command line at startup? You need to make run level 3 as default by modifying the following line in the /etc/inittab file (you’ll not find this file in Linux with Systemd system manager):

Similarly, replace 3 with 5 to make GUI as default run level in Linux.

Systemd-Based Boot Target In Linux

Currently, the majority of Linux distributions have already replaced the old init system with the modern systemd system manager. Hence, instead of the runlevel concept, we need to use the Systemd-based target concept to switch between CLI and GUI in Linux.

Similar to runlevel 3 for CLI and runlevel 5 for GUI, systemd has a corresponding target multi-user.target for CLI and graphical.target for GUI.

Читайте также:  Как узнать версию ssh linux

By executing the below command, you can list all systemd active targets:

$ systemctl list-units --type target

List Systemd Targets

Switching Boot Targets Between CLI and GUI in Linux

Now, to change the target manually or switch to command line mode from GUI, you can use the systemctl command with isolate subcommand in the given below format:

$ sudo systemctl isolate multi-user.target

To switch back to GUI from command line mode, specify graphical.target with the command:

$ sudo systemctl isolate graphical.target

Set A Default SystemD Target in Linux

As you boot the Linux system, it loads the default target. So, you can identify the current default target using the systemctl command along with the get-default subcommand:

$ sudo systemctl get-default

And to change the current target and set it as default for all next boot, use the set-default option with multi-user.target for CLI or graphical.target for GUI as argument:

$ sudo systemctl set-default multi-user.target [For CLI] $ sudo systemctl set-default graphical.target [For GUI]

Next, reboot the system to apply the default target:

Keyboard Shortcut To Switch Between CLI and GUI

If you already have a desktop environment on your Linux system, you can also switch between your graphical desktop and command line text mode by simply pressing CTRL + ALT + N . Here Replace N with numbers 1 to 7.

Linux has by default six text terminals and one graphical terminal. So, to switch to command line mode, you can press CTRL + ALT + F1/F2/F3/F4/F5/F6 and switch back to the graphical mode by pressing CTRL + ALT + F7 .

Keyboard Shortcut is only helpful temporarily as we cannot use it set the default mode for permanent the way we can in the above Init or Systemd-based methods.

Conclusion

Though GUI is the most prevalent way of using Linux systems, CLI is still relevant as it helps in troubleshooting if GUI fails or system resources is too less to support GUI.

That is why it’s worth knowing how we can switch between graphical and command modes and also set either as default. As we learned, this can be done in various ways like by the modern way of changing the boot target in systemd, Keyboard shortcuts, and legacy init system manager.

Источник

How to switch between the CLI and GUI on a Linux server

Learn how to change between the command-line interface and the graphical user interface by editing the boot target.

Command line output in the terminal

What do you do if your server boots to a graphical user interface (GUI), but you need it to boot to the command-line interface (CLI) for security and performance reasons? In days past, you would have edited the /etc/fstab file so that, instead of booting to runlevel 5 (the GUI), it booted to runlevel 3 (the CLI). However, with the advent of the systemd system manager, you must do something a bit different.

Training & certification

First, you no longer use the runlevel term. Instead, you refer to boot choices as targets. The two primary targets for this scenario are multi-user.target (the CLI) and graphical.target (the GUI). The multi-user.target may be loosely associated with the legacy runlevel 3 concept, while the graphical.target is similar to runlevel 5.

Читайте также:  Linux установленные версии ядер

It’s possible to switch targets manually, and you can also configure automatic or default boot targets. This article aims to explain both options.

Identify the current target

It’s probably clear when you boot the system which target is the default. However, to confirm the default, use the systemctl command along with the get-default subcommand:

$ sudo systemctl get-default

The result will likely display either the multi-user.target or graphical.target.

Change targets manually

You can switch between targets on the fly by using the isolate subcommand. Perhaps you have a long checklist of administrative tasks, and it would be simplest for you to accomplish these in a GUI, but your server boots to the CLI. You can switch to the GUI, perform your tasks, and then switch the system back to the more efficient CLI.

Here’s the command to launch the GUI from the multi-user.target:

$ sudo systemctl isolate graphical.target

Switch back by specifying the multi-user.target with this command:

$ sudo systemctl isolate multi-user.target

Those commands are useful for the current runtime, but what about configuring a default for when the system boots?

Set a default target

The default target represents the interface presented when the system first boots. Booting a server to a CLI for efficiency and security is common. The CLI consumes far fewer resources and contains less software to patch and worry over. Newer administrators or those migrating from another server platform may not be comfortable enough with Bash to work effectively at the command line. End-user workstations rarely boot to the CLI because the user typically needs graphics-based software, such as productivity suites and web browsers. For these users, the performance hit is worth the convenience.

Use the following systemctl command to configure the default startup target as the CLI:

$ sudo systemctl set-default multi-user.target

Use the graphical.target argument to set the GUI as the default.

Try it

Try the following exercise if you have a systemd-based distribution available, such as Red Hat Enterprise Linux (RHEL).

Check the current default target:

$ sudo systemctl get-default

Switch to the opposite target (for example, if your system boots to the GUI, switch to the CLI):

$ sudo systemctl set-default multi-user.target

Reboot and confirm the appropriate target launched:

$ sudo systemctl isolate graphical.target

Configure the system back to the original target:

$ sudo systemctl set-default graphical.target

Reboot and then confirm the default target:

If you don’t have access to a system to experiment with, I encourage you to create a simple lab environment for these types of learning opportunities.

Understand target files

Targets are managed by .target files that simply group units and dependencies into a convenient format. It’s really the .unit files that define exactly what services and other features start when the target is initiated. Enabling and disabling services and daemons adds and removes these components from the startup options:

$ sudo systemctl enable sshd $ sudo systemctl disable sshd

Источник

Оцените статью
Adblock
detector