Learning Linux For Beginners 1
30 April 2008 at 11:40 am 1 comment
Peace to you all.
In this series, I will try to discuss to you the Linux essentials commands and operations. I will begin from zero to learn Linux for beginners, also other people may know some new information.
The Terminal
A “terminal” is a way of typing commands to the computer. That may sound very strange, but it’s actually really, really nice and easy once you get used to it. You can either open a terminal inside of your graphical environment, or you can switch your whole screen to a terminal. You can use any graphical system you need like Fedora, OpenSuse, or Ubuntu.
To open the terminal from the graphical system :-
In Fedora –> Open main menu then System then Terminal
In Ubuntu –> Open main menu then Accessories then Terminal
To switch you entire screen to console, press Ctrl-Alt-F1. You can then switch between six different terminals, by using Alt-F1 through Alt-F6. Pressing Alt-F7 will bring you back to your graphical environment.
The Basic Operations
The su (short for substitute user) command makes it possible to change a login session’s owner (i.e., the user who originally created that session by logging on to the system) without the owner having to first log out of that session.
Although su can be used to change the ownership of a session to any user, it is most commonly employed to change the ownership from an ordinary user to the root (i.e., administrative) user, thereby providing access to all parts of and all commands on the computer or system. For this reason, it is often referred to (although somewhat inaccurately) as the superuser command. It is also sometimes called the switch user command.
In ubuntu we use the command : sudo -s to do the same functionality.
Advantages of Using su
su is usually the simplest and most convenient way to change the ownership of a login session to root or to any other user.
More importantly, it provides a safer way for administrators on multi-user systems (as well as for users on home computers or other single-user systems) to use the system than to routinely log on as the root user. That is, there is much less potential for accidental or malicious damage if an administrator first logs on as an ordinary user (who, by default, has very limited system privileges) and uses that account for routine tasks that do not require root’s sweeping powers. su can then be used to switch to the root account for only those operations that actually require root access (e.g., making system repairs and managing user accounts).
The use of su instead of routinely logging in as root is particularly important when connected to the Internet. This is because it makes it much more difficult for malicious software originating on remote computers to access critical system files or commands (which belong to the root account).
On multiuser systems, not only the root account but also su should be used to the minimum extent necessary, and it should be used with great caution. This includes making certain (1) that no unauthorized persons see any passwords used with su (such as watching a password being typed in or seeing it on paper), (2) that su sessions are not left unattended and (3) that su sessions are terminated as soon as the tasks for which they were invoked have been completed.
When su is used while in console mode (i.e., with a text-only screen display), the original user’s session cannot, of course, be used on the same machine (because the su session occupies the entire screen). However, when su is used in a terminal window (i.e., a text-only window in a GUI), only that terminal window and programs that are started from it are run with the new user’s account (e.g., root), and all other programs, including any other terminal windows, can continue to be run by the original user.
A convenient way of eliminating the need for typing su numerous times during a session is to open a terminal window, run su once in that window and then use the window for all root tasks (i.e., tasks for which administrative privileges are required) during the session. However, it is important to make certain that no one has physical access to the computer during such session. Thus, it is advisable to close the terminal window as soon as practical, unless it is used on a home system (where, presumably, nobody is around to cause damage to the system or steal data).
Another advantage of using su is that a record is kept of its usage in system logs, whereas no such record is kept if one logs in directly as root.
Syntax
A simplified expression of the syntax of the su command is:
su [options] [commands] [-] [username]
The square brackets indicate that the enclosed item is optional. Thus, the simplest way to use the su command is to just type:
su
The operating system assumes that, in the absence of a username, the user wants to change to a root session, and thus the user is prompted for the root password as soon as the ENTER key is pressed. This produces the same result as typing:
su root
If the correct password is provided, ownership of the session is changed to root.
Likewise, to transfer the ownership of a session to any other user, the name of that user is typed after su and a space. For example, to change the owner of the current login session to a user named alice, type the following:
su alice
The user will then be prompted for the password of the account with the username alice.
Tail a Log with su
A major benefit of using su is that a record is kept of its usage in a system log, typically /var/log/messages. This is particularly valuable if there are multiple administrators for the system (each of which should have an individual username and password), because it facilitates finding out who was doing what and when. /var/log/messages records the username and user ID (UID) of the user that opens a su session as well as the times that the session is opened and closed. However, su does not keep a record of what is actually done as root, and such information must therefore be obtained from other sources.
The contents of /var/log/messages can be viewed by first using su to switch to the root account and then issuing the following command:
tail /var/log/messages
It is convenient to use the tail command here because it shows the last part of a file, rather than starting at the beginning as commands such as cat (possibly the most commonly used command for reading text files) do. As /var/log/messages can be a rather long file, this can save a lot of scrolling.
Tail prints (i.e., writes to the monitor screen) the final ten lines by default, but this can be easily adjusted by using the -n option followed by a space and an integer representing the desired number of lines. For example, the following command would print the final 20 lines of /var/log/messages:
tail -n 20 /var/log/messages
As is the case with many command line programs, there is a graphical front end available for su, and it is named KDE su. A graphical front end is a GUI program that operates on top of a command line program and replaces its character-based user interface with a graphical one.
su is one of the GNU Core Utilities, which are developed by the Free Software Foundation (FSF) and are therefore open source and free to use, study, modify and redistribute. KDE su is also free software.
Entry filed under: Linux. Tags: Learning Linux, Learning Linux For Beginners, Linux, Linux Terminal, su command, tail command.
1. oyabunbaba | 7 January 2012 at 9:09 pm
Wow, nice long article, hope more ppl will use Linux, coz IMHO it’s easier to use than Windows, eg. in 95% no need to install drivers, all programs are in Software Center soo, no need to search exe’s all over internet, and thats why no viruses.