Unit 2
Unit 2
Before you start, your system must be ready to use. Your system is ready to use when Solaris is fully
installed, and the login prompt is on the screen. If Solaris is not installed, refer to the installation
manual for your specific platform.
When you begin working on your system, you will need to log in. Logging in tells the system who you
are and what you have permission to do. Likewise, when you finish, you will log out so that no one
else can access your files without permission.
Logging In
Since more than one person can have an account on a single system, each user must log in using his
or her own unique user name and password. Logging in indicates who is using the system and what
files they can access.
To log in:
1. Type your user name at the login prompt and press Return.
The user name tells the system who you are. Your user name should have been defined during
installation. For more information, refer to the installation manual for your specific platform. The
Solaris operating environment recognizes the difference between uppercase and lowercase letters, so
make sure you type the user name using the correct case.
The login prompt usually consists of your machine name (assigned as the Hostname during the
installation) followed by the word login:, as shown in the example
1.
You do not see the characters on the screen as you type your password, as shown in the example
in Table 1-2.
Password:
If you mistype the user name or password and have already pressed Return, the system asks you to
start over with your user name. See the example in Table 1-3.
Password:
Login incorrect.
login:
After you type your password, OpenWindows launches automatically ( if a full installation was
performed.)
Logging Out
When you are done working on the system, you will need to log out. If you are sharing a system, this
allows other people to log in to your computer under their own accounts.
To log out:
1. You must exit OpenWindows to log out. Press the MENU button and select Exit.
A Notice appears asking you to confirm that you want to exit from OpenWindows.
2. SELECT Exit.
Normally, when you exit OpenWindows, the system automatically logs you out. However, if it does not,
go to Step 3.
The login: prompt appears, as shown in the example in Table 1-4. Now another user can log in under
their own account and use the system.
genius% johndoe
genius login:
The Linux command is a utility of the Linux operating system. All basic and advanced tasks can be
done by executing commands. The commands are executed on the Linux terminal. The terminal is a
command-line interface to interact with the system, which is similar to the command prompt in the
Windows OS. Commands in Linux are case-sensitive.
Linux terminal is a user-friendly terminal as it provides various support options. To open the Linux
terminal, press "CTRL + ALT + T" keys together, and execute a command by pressing the 'ENTER'
key.
A shell is a software program used to interpret commands that are input via a command-line
interface, enabling users to interact with a computer by giving it instructions.
What's a "Terminal?"
It's a program called a terminal emulator. This is a program that opens a window and lets you interact
with the shell. There are a bunch of different terminal emulators we can use. Some Linux distributions
install several. These might include gnome-terminal, konsole, xterm, rxvt, kvt, nxterm,
and eterm.
Some basic command in linux
1. pwd Command
The pwd command is used to display the location of the current working directory.
Syntax:
1. pwd
Output:
2. mkdir Command
The mkdir command is used to create a new directory under any directory.
Syntax:
1. mkdir <directory name>
Output:
3. rmdir Command
The rmdir command is used to delete a directory.
Syntax:
1. rmdir <directory name>
Output:
4. ls Command
The ls command is used to display a list of content of a directory.
Syntax:
1. ls
Output:
5. cd Command
The cd command is used to change the current directory.
Syntax:
1. cd <directory name>
Output:
7. cat Command
The cat command is a multi-purpose utility in the Linux system. It can be used to create a file, display
content of the file, copy the content of one file to another file, and more.
Syntax:
1. cat [OPTION]... [FILE]..
To create a file, execute it as follows:
1. cat > <file name>
2. // Enter file content
Press "CTRL+ D" keys to save the file. To display the content of the file, execute it as follows:
1. cat <file name>
Output:
8. rm Command
The rm command is used to remove a file.
Syntax:
rm <file name>
Output:
9. cp Command
The cp command is used to copy a file or directory.
Syntax:
To copy in the same directory:
1. cp <existing file name> <new file name>
To copy in a different directory:
Output:
10. mv Command
The mv command is used to move a file or a directory form one location to another location.
Syntax:
1. mv <file name> <directory path>
Output:
grep Command
The grep is the most powerful and used filter in a Linux system. The 'grep' stands for "global regular
expression print." It is useful for searching the content from a file. Generally, it is used with the pipe.
Syntax:
1. command | grep <searchWord>
wc Command
The wc command is used to count the lines, words, and characters in a file.
Syntax:
1. wc <file name>
Output:
cal
The 'cal' term stands for calender. It displays current month's calender with current day highlighted.
Syntax:
1. cal
Look at the above snapshot, cal command has highlighted current date in current month.
whoami
It tells you about the system's username.
Syntax:
1. whoami
who am i
This command displays the information about the current user only.
Syntax:
1. who am i
Look at the above snapshot, in our system current logged in user is sssit.
w
This command tells about the users who are logged in and what are they doing.
Syntax:
1. w
id
This command tells about your user id, primary group id, and a list of groups that belongs to you.
Syntax:
id
Linux Create User | Linux Add user | Linux user add command
The Linux server allows us to create more than one user after installation. Linux is a Multi-user system,
which means more than one user can work in the same system at the same time. We are allowed to do
so through the Setup agent.
We must have to create an account in order to work with Linux
as we cannot keep working with the root account. We have one administrative account; a system
administrator account is responsible for managing the user accounts and groups of the system.
Adding or removing a user is one of the most basic tasks of a new Linux server.
We are given only a root user account by a new Linux server. Adding a user account provides lots of
power and accessibility to a particular user. It is a useful but insecure utility of the Linux server. It is
good to add an unprivileged user to do common tasks. However, we can access the administrative
privilege through sudo command-line utility.
In Linux, useradd command is a command-line utility which is used to add or remove a user on a
Linux server and Unix based operating system.
In a different type of Linux distribution, the useradd command may be slightly different.
The useradd command performs the below tasks:
o It edits the files for newly created user
like /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow.
o It creates and opens a new home directory.
o It allows us to set ownerships and permissions to the home directory.
Syntax:
1. useradd [options] username
In order to use the useradd command, we have to log-in with root or sudo access.
Before using Linux useradd command, let's understand some common terms that are used in the Linux
command line.
o Username: A username is a name that is used to login to the Linux system. It is displayed
when we turn on our machine. The username length should be between 1 to 32 characters.
Password: A password is a secret code that is used to protect your system from unauthorized access.
It is stored in etc/shadow file in an encrypted format.
User ID (UID): Linux provide a unique Id to every user; it is called user identification
number or User ID or UID. By default, the UID for the root user is reserved as zero, and the
remaining UID from 1 to 99 is reserved for other predefined accounts. Further, UID's from 100-999 are
reserved for groups and system accounts.
Group ID (GID): The GID or Group ID is a group identification number provided by the Linux system.
It is stored in /etc/group file.
User Info: It allows us to define some additional information about the user, such as user full name. It
is optional.
Home Directory: It is an absolute location for a user.
Shell: It is an absolute location of a user's shell i.e. /bin/bash.
To create a new user by useradd command, execute the useradd command followed by username as
follows:
1. sudo useradd JTP3
The above command will ask for the system administration password, enter the password. It will create
a user named as JTP3. This username is used by the user to login the system. The username must be
unique. Consider the below output:
To set the password for the newly created user, execute the below command:
1. sudo passwd JTP3
The above command will ask for the new password, enter the password and retype the new password.
It will update the password for the specified user. Consider the below output:
It will be useful when you want to create an account for any user who is going to depart after a short
period.
root
The root user is the superuser and have all the powers for creating a user, deleting a user and can
even login with the other user's account. The root user always has userid 0.
useradd
With useradd commands you can add a user.
Syntax
useradd -m -d /home/<userName> -c "<userName>" <userName>
Example:
useradd -m -d /home/xyz -c "xyz" xyz
Look at the above snapshot, we have created a user xyz along with creating a home directory (-m),
setting the name of home directory (-d), and a description (-c).
The 'xyz' received userid as 1004 and primary group id as 1004.
/etc/default/useradd
File /etc/default/useradd contains some user default options. The command useradd -D can be used
to display this file.
Syntax:
useradd -D
userdel
To delete a user account userdel command is used.
Syntax:
userdel -r <userName>
Example:
Linux Groups
Users can be listed in different groups. Group allow us to set permission on the group level instead of
setting the permission on individual level.
Every Linux distribution have a graphical tool to manage groups. Groups can be managed by graphical
tools, command line tools and by vi or vigr depending upon the user's experience. Only experienced
users should use vi or vigr to manage groups, since it will do proper locking or changes in the file.
groupadd
The groupadd command creates or add a group in our system.
Syntax:
1. groupadd <groupName>
Example:
1. groupadd php
2. groupadd java
3. groupadd android
4. groupadd spring
Look at the above snapshot, groups php, java, android and spring are created with groupadd
command.
Group File
The /etc/group file defines the group membership. A user can be a member of more than one group.
Syntax:
1. /etc/group
Look at the above snapshot, first column indicates group name, second is the group's encrypted
password which may remain empty also, third is group identification (GID) and fourth is the list of
members. Fourth list is empty as these groups do not have members.
Groups
The group command tells about the group where current user belongs to.
Syntax:
1. groups
Look at the above snapshot, user jtp and sssit belongs to the different groups.
usermod
The group members can be edited with usermod or useradd command. If a group is not listed then
by default, usermod command will remove the user from every group of which he is a member. Here, -
a (append) option is used to prevent this from happening.
Syntax:
1. usermod -a -G <group> <userName>
Example:
1. usermod -a -G php akki
2. usermod -a -G php abc
3. usermod -a -G java jtp
Look at the above snapshot, we have displayed the list of /etc/group. User akki and abc are added
into the group php, user jtp is added into java.
gruopdel
The command groupdel will delete a group permanently from the system.
Syntax:
1. groupdel <group>
Example:
1. groupdel sql
Look at the above snapshot, group sql is deleted from the system.
gpasswd
Control of group membership can be passed on to another user with gpasswd command.
Syntax:
1. gpsswd -A <user> <group>
Example:
1. gpasswd -A jtp java