Archive

Posts Tagged ‘command line’

Beginner’s Guide to Command Line: Part II

August 9, 2008 Leave a comment

Understanding Users

Who you are as a user on the Linux system is important to understanding what you can do. Just like Windows, Linux is a multi-user operating system and all users do not possess the same rights. There are three basic types of users on the Linux system; the root user, normal user accounts and the service users.

The root user account is created by the operating system when it is installed. This user is the superuser who basically has complete control of the entire system. This means that great care should be taken to preserve the integrity of this account. One aspect of this care is to ensure that the root password is complex and changed on a regular basis. In addition, the root account should not be used to log into a server because if anyone gains access to the root account they have complete control of all services and information located on the server.
Service accounts such as apache, squid, cups, etc. are each created when the service is installed. Typically there is no need to change these accounts. These accounts often are accounts that cannot be used to log into the server. A number of service accounts cannot be used to log into the system. This is simply a security matter and should not be changed nor will it offer any problems.
Normal users are users that are created on Linux file system and have a home directory in /home. So if you had 4 users on the system called; fred, jane, mary and tom you would see these /home directories.

/home
/fred
/jane
/mary
/tom
Normal Users
Normal users do not all have the same privileges. The fist user created on the system can use a special command called “sudo” to gain root privileges so that this account could be used to manage a server or desktop. Other users do not by default have these rights nor can they gain these rights unless the root user provides them with those special rights.

Typically users can do anything they want in their own home directories. They can create, copy or delete files and directories in their home. They also have the rights to read just about any file on the entire Linux system. That means that they can read any of the configuration files in the /etc directory or any of the program listings in the /usr directory. Normal users can move all around the file system. There are very few limitations, one of those is the /root directory. No user is allowed to view or move into the /root directory which is the home directory for the root user.
The implications of a normal user in the file system is that they can only save files or backups to their own home directory, they will not be able to save anywhere else.

When users are created they will also be created as a member of a group with the same name. So when the user tom is created, immediately the group tom is created with the user tom being the only member. Groups allow several users to share files if they needed to. Here are a few examples.
User Group
tom tom
jane jane
mary mary
fred fred, tom, mary
In the examples above, each user is created and the group with their name is also created. However, when you look at the group fred both tom and mary have been added to that group so that fred, tom and mary could share files that were owned by the group.
A user’s login name must be unique and less than 32 characters. It may contain any characters except colons and new lines. Typically login names are lower case, some Linux distros require lower case. When you create login names a standard is important as these names also reflect what will be available for email addresses.
User passwords are encrypted and kept in a separate file which is not available to anyone but root. This file is /etc/shadow. Passwords must be encrypted which means they must be created with the passwd command or encrypted and copied to the account. However, editing accounts by hand is filled with possibilities of mistakes so should be avoided. Most Linux distributions use the MD5 encryption which allows for random lengths in passwords.
When users are create d they will get a login name for the users to recognize but the system will user a UID or User Identification number. These numbers will begin at either 500 or 1000 and be incremented by one for each new user. So if you create the user tom and tom is the first user to be created he will have a UID of 1001.
tom 1001
mary 1002
jane 1003
fred 1004

In addition to UIDs that are created, a GID or Group Identification number is also created for each user name. The GID is a private group with Ubuntu which means that no other users have read access to a user’s files. If tom is the first created user and his UID is 1001 he will also have a GID of 1001. Again, the numbers that relate to the users is for the operating system. Here are some examples.
User UID GID
tom 1001 1001
mary 1002 1002
jane 1003 1003
fred 1004 1005
Note that the UID and the GID do not have to be the same. If you created a special group before you created fred then all the rest of the numbers will be out of sync which is not a problem but something you need to be aware of.

The root User

The root user is the superuser on the system. Root has access to all files and directories on the system and is able to configure all aspects of the system. The UID for root is 0, which you can see in /etc/passwd. There should only be one user with a UID of 0 on the system as this could lead to serious security abuse. Many activities on the system are limited to the root user only. Changes like creating device files, setting the hostname, configuring network interfaces, working with privileged network ports (below 1024) are examples of activities that can only be performed by root. This is a powerful and yet dangerous account as root can make, and will make mistakes that could take the system down.

root Login
Best security practices suggest that you never login as root. When you login as the administrator of the Linux system you need to recognize the dangers of allowing the server to run as root. Any access gained into the system as root user will give intruders complete control of the server. If you login as a normal user this means that you must become root using the “su root” command. This is simply to protect your system when online since if the system was cracked when you are logged in as a regular user there is much less damage done than if you were logged in as root, allowing full access. The issue is file and directory ownership and access. User Identification numbers (UID) and Group Identification numbers are mapped to each user and group and recorded in /etc/passwd and /etc/group. These UIDs and GIDs are used to determine ownership and access to files and directories. In addition, users run processes and the owner of a process can send process signals that can impact the process activity.

The root user is intended to run many commands that are not available to other users of the operating system. Here are several directories that are intended only for the root user:
/sbin – This directory contains commands for modifying disk partitions (fdisk), changing boot procedures (lilo), and changing system states (init).
/usr/sbin – This directory has commands for managing user accounts (adduser), configuring the mouse(mouseconfig) or keyboard (kbdconfig). Most daemon processes are also in this directory.
/bin and /usr/bin contain commands that both root and users will use. For example: /bin/mount is a command that root will mount directories but users will use this command to list mounted directories.
The /usr/share/man/man8 directory lists many of the commands that are intended for use by the system administrator.

Beginner’s Guide to Command Line: Part 1

August 9, 2008 Leave a comment

The command line interface will either be from a terminal or a SSH window like putty. Here is an example of the Gnome terminal (Applications/Accessories/Terminal from the menu). You can see that it is only text but it does have a menu system for modifying the color of the screen and text or allowing you to open multiple terminals at one time.

If you login from a putty session from a Windows machine or if you are logged into a TTY session on the Linux box you will not have the option of a terminal and so you will be using text only as there will be no menus or graphics of any kind. Text is exactly the same as you can see in the next example. The biggest difference is that it will typically be a black screen with white text.

As you change users the prompt will show the change in user as you can see from these examples:

fred@ub:~$
mary@ub:~$
tom@ub:~$
jane@ub:~$

As you change to different servers the hostname will change. The hostname is a name that is applied to a server so that users and applications may refer to the server with a name and not an IP Address. An example would be of a hostname of ub instead of the IP Address 192.168.5.43. As you connect to different servers or workstations, this name will change. These names can be anything the system administrator would like to assign.

fred@mail:~$
fred@ftp:~$
fred@ubuntuserver:~$
fred@mystuff:~$

As you change locations in the file system the location will change. The ~ symbol indicates that a user is located in their home directory. The home directory in Linux is located in a directory, Windows calls them folders, labeled /home. So if fred is in his home directory he is really located in /home/fred. Each user has a home directory named for the user. If fred changes location in the directory system to /var, his prompt will reflect that change.

fred@ub:/var$

If mary changes to the /usr/share directory it will reflect that change.

mary@ub:/usr/share$

If tom changes to the /usr/bin directory it will reflect that change.

tom@ub:/usr/bin$

And finally if jane moves to the / directory it will reflect that change.

jane@ub:/$

Changes in location in the file system will list the location in the prompt. It is important that you use this as a clue to location especially when you begin to issue commands.

Follow

Get every new post delivered to your Inbox.

Join 58 other followers