Definition of terminal/konsole

A terminal, also called console and in KDE konsole, is a program that makes it possible to interact directly with the Linux operating system by issuing various commands which are then executed immediately. Also often referred to as a 'shell' or 'command line', the terminal is a very powerful tool and it's well worth the effort to gain some basic understanding of its use.

In aptosid you can find the terminal/konsole close to the K-menu symbolised by a PC monitor. Depending on your theme it may or may not also contain the image of a shell. You will also find the same icon in the K-menu under "System".

When you open a terminal window you will be presented with the terminal prompt which will have the format of:

username@hostname:~$

You should recognise the username as your own login name. The ~ (tilde) indicates that you are in your home directory and $ indicates that you are logged in as a user. At the end you will have your cursor. This is your command line where you will enter the commands you want to execute.

A lot of commands need to be run with root privileges. To achieve this you type:su at the prompt and press enter. You will then be asked for your root password. Type your password and hit enter again (note that when you type your password, nothing will show on the screen).

If your password is correct the prompt will change to:

root@hostname:/home/username#

WARNING: While you are logged in as root, the system will not stop you from doing potentially dangerous things like deleting important files etc., you have to be absolutely sure about what you are doing, because it's very possible to seriously harm your system.

Note that the $ sign has changed into a # (hash). In a terminal/konsole the # always indicates that you are logged in with root privileges. Throughout this manual we will omit everything in front of the $ or the #. So a command like:

# apt-get install something

Means: Open a terminal, become root (su) and enter the command at the # prompt. (Don't type the #)

Sometimes a konsole and/or terminal may become corrupted, type:

reset

and hit enter key.

If a konsole and/or terminal's output appears distorted. You can often cure this problem by pressing ctrl+l, which redraws the terminal window. This distortion happens mostly when working with programs that use the ncurses interface, such as irssi.

A konsole and/or terminal on occasion may appear to be frozen, however, it is not, and anything you type will still be processed. This can be caused by pressing ctrl+s accidentally. In this case, try ctrl+q to unlock the terminal.

Coloured terminal user:~$ and root:# prompts:

Coloured terminal prompts could save you from making an embarrassing and a possibly catastrophic mistake while as root # when you really wanted to be as user~$, or to use prompt colours as a marker to commands you executed a few 100 lines ago.

By default, both user~$ and root# prompts are the same colour and it is really easy to change the colours for both accounts.

The basic colours are:

(the syntax is 00;XX)
[00;30] Black
[00;31] Red
[00;32] Green
[00;33] Yellow
[00;34] Blue
[00;35] Magenta
[00;36] Cyan
[00;37] White
[Replace [00;XX] with [01;XX] to get a colour variation].
To change your username ~$ prompt colour:

As $ user, with your favourite text editor:

$ <editor> ~/.bashrc

Go to line 39 and uncomment it, thus:

force_color_prompt=yes

Go to line 53 and where it has 01;32m, (for example), change it to a colour that suits you.

As an example, for a cyan coloured user~:$ prompt, [01;36m\], you will need to change the code [01;XXm\] in 3 places within the syntax:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u@\h\[\033[01;36m\]:\[\033[01;36m\]\w\[\033[00m\]\$ '

The new look will only appear in new terminal sessions.

To change your root# prompt colour:
su
<mcedit> /root/.bashrc

Go to line 39 and uncomment it, thus:

force_color_prompt=yes

Go to line 53 and where it has 01;32m, (for example), change it to a colour that suits you.

As an example, for a red coloured root:# prompt, [01;31m\], you will need to change the code [01;XXm\] in 3 places within the syntax:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[01;31m\]:\[\033[01;31m\]\w\[\033[00m\]\$ '

The new look will only appear in new terminal sessions.

Terminal background colours

To change the background colour and font options of the terminal, look at the menu options of the terminal.

Terminal colours

There are a plethora of options available for changing colours, however the recommendation is to keep it simple.

About Xapps whilst in X as root and sux2 as an alias

While the common command for becoming root is <su>, using kdesu <Application> or gksu <Application> will allow you run GUI / X11 applications from the desktop and allow root to start graphical applications.

For those used to using sux , (sux has been broken by a 'login' security update for a long time), will find that sux2, as an alias, is a good option in the meantime otherwise use, as $user:

$ suxterm

In most cases, using an Xapp while in root is to take advantage of a GUI editor like kate, kwrite, mousepad or leafpad to name just a few. X while in root is also required for the GUI partitioning application gparted. (Also see sudo).

Non-gui applications like mcedit, vim, vi, or emacs are highly recommended as editors, with mcedit being one of the intuitive editors of the non-gui applications for use by first time users of a text editor while in root with X. mcedit, vim, vi or emacs are possibly your only choices of an editor while not in X. (mc is an ideal file browser while not in X).

KDE options

To start kdesu in KDE:

Alt+F2

or right-click on the desktop and choose:

Run Command

then:

kdesu <Application>

Some KDE applications require dbus-launch in front of the application:

dbus-launch <Application>

Xfce options

To start Run Command in Xfce:

Alt+F2

or right-click on the desktop and choose:

Run Command

then:

gksu <Application>

Other Desktop Window Manager options

Another keyboard option also generic to all major Desktop Managers is:

Alt+F2

then:

su-to-root -X -c <Application>

Terminal/konsole options

To run kdesu in a terminal:

/usr/lib/kde4/libexec/kdesu

To run gksu in a terminal:

/usr/bin/gksu

Another option is ssh -X root@localhost otherwise use su-to-root -X -c :

ssh -X root@localhost

Whilst ssh is installed by default it may not be enabled. To enable ssh, as root:

service ssh start

else:

su-to-root -X -c <application>

Setting up an alias in a the terminal for kdesu, gksu, su-to-root -X -c or ssh -X root@localhost called sux2

Typing a long command line in the terminal all the time is not an ideal, so the solution is to set up an terminal/konsole alias called sux2.

Note: In each of the following examples the command to activate the alias in a terminal will be:

sux2 <application>
Setting an alias

The use of mcedit as $user in the following examples is deliberate. Feel free to use any editor you wish to use:

$ mcedit ~/.bashrc

Note:To enable any changes you have made you need to close the terminal/konsole and restart it.

Add the following code to the file ~/.bashrc by appending the code to the end of the file:

Setting kdesu an alias

alias sux2='/usr/lib/kde4/libexec/kdesu' 

Setting gksu an alias

alias sux2='/usr/bin/gksu'

Setting su-to-root -X -c as an alias

alias sux2='su-to-root -X -c'

Setting ssh -X root@localhost as an alias

alias sux2='ssh -X root@localhost'

You may want to implement a ~/.bash_alias file to contain all the aliases that you find useful. Therefore make a file called ~/.bash_alias. Read the ~/.bashrc file and /usr/share/doc/bash-doc/examples:

apt-get install bash-doc

sudo is not supported

sudo is not enabled by default on installation to hard disk. It is available for use on a live-ISO since no root password is preset. The reasoning behind this is so that if an attacker gets hold of the users password, they do not immediately get full super-user privileges and make potentially damaging changes to your system.

Another issue with sudo is that it leads to running a root application with a users configuration, which may override or change permissions. In some cases, this can subsequently make an application unusable for the user. Use sux2, kdesu <application>, gksu <application> su-to-root -X -c <application> or ssh -X root@localhost as recommended.

Being in root

WARNING: While you are logged in as root, the system will not stop you from doing potentially dangerous things like deleting important files etc., you have to be absolutely sure about what you are doing, because it's very possible to seriously harm your system.

Under no circumstances should you be as root in the console/terminal to run applications that a standard user uses to go about being productive on a day to day basis, like sending emails, creating spreadsheets or surfing the internet and so forth.

Command Line Help

Yes there is. Most Linux commands/programs comes with its own manual called a "man page" or "manual page" accessible from the command line. The syntax is:

$ man command-name

or

$ man -k <keyword>

This will bring up the manual page for that command. Navigate up and down with the cursor keys. As an example try:

$ man apt-get

To escape from the man pages type q to quit

Another useful utility is the "apropos" command. Apropos basically enables you to search the man pages for a command if you e.g. don't remember the complete syntax. As an example you can try:

$ apropos apt-

This will list all commands for the package manager 'apt'. The 'apropos' utility is a quite powerful tool, but describing it in detail is way beyond the scope of this manual. For details of its use, see it's man page.

Linux Terminal Commands List (excerpt)

This is an excellent primer on using BASH from linuxcommand.org

A very comprehensive list of commands in alphabetical order from An A-Z Index of the Bash command line for Linux and is a 'must bookmark'

There are numerous tutorials on the Internet. A very good one aimed at the beginner is: A Beginner's Bash

Or use your favourite search engine to find more.

Page last revised 05/03/2013 1326 UTC