Download SLIDE-Labs-C01-Linux-EN.pdf
Download Labs-C01-Linux-EN.pdf
Getting started with the shell
The ls command
- Read the 'ls' manual to explain the result of the following command:
To find the information in the man, type "/" and a string you want to find. To quit man, type 'q'
isen@name_s_client ~ $ ls -a -l -r -t /home/isen
- Some command allow you to 'concat' the arguement. You can do the same with :
isen@name_s_client ~ $ ls -alrt /home/isen
- The order is not important for THIS command :
isen@name_s_client ~ $ ls -tral /home/isen
- Compare this 2 command and explain the difference :
isen@name_s_client ~ $ ls -1 /home/isen
isen@name_s_client ~ $ ls -1a /home/isen
-
Give the size of /bin/cat in a 'human' way, (i.e. in KB, MB or GB depending on the size of the file)
-
You are in your home directory, list with ls the contain of the Notes directory with the absolute way and the relative way.
The cd command
- Read the simple 'cd' manual to explain the result for each following commands :
isen@name_s_client ~ $ cd .
isen@name_s_client ~ $ cd ..
isen@name_s_client /home $ cd /home/isen
isen@name_s_client ~ $ cd ../..
isen@name_s_client / $ cd ./home/isen/
isen@name_s_client ~ $ cd ../../
isen@name_s_client / $ cd ../../var/log
isen@name_s_client /var/log $ cd ../../home/isen
isen@name_s_client ~ $ cd .././isen/
isen@name_s_client ~ $ cd ./../isen/
isen@name_s_client ~ $ cd ../../tmp/../etc/../var/log/../tmp/./../../home/isen
-
In absolute path move into the /etc direcory
-
In relative path go back in your home directory
The pwd command
-
Type pwd and observed that the Prompt say '~' and the output of the command is /home/isen
-
With cd change your directory to /tmp in absolute way
-
Type pwd what did you observed in the prompt ?
-
Type cd with no argument. What happened ?
-
With cd change your directory to /tmp and type cd ~isen . . What happened ?
The touch command
-
change your direcory to /home/isen/Notes/C01
-
With pwd, check you are in the good directory
-
With touch create the files MyFirstFile in /home/isen/Notes/C01 with the abolute way
-
With touch create the files MySecondFile in /home/isen/Notes/C01 with the relative way
-
With stat check the file MyFirstFile
-
Read the 'touch' manual to change the modification time of MyFirstFile and check with stat to compare
The mkdir command
-
Create with mkdir the directory /tmp/C01
-
Try to create the directory '/tmp/TP01/sample', what is the message
-
Find in the man of mkdir the way to create this directory in one command and create the directory '/tmp/TP01/sample'
The cp command
-
Go back in your home directory with cd
-
With the cp command, copy the file /home/isen/Notes/C01/MyFirstFile into /tmp/TP01/sample/ with the abolute way
-
With the cp command, copy the file /home/isen/Notes/C01/MySecondFile into /tmp/TP01/sample/ with the relative way
-
With the cp command, copy the file /etc/hostname into /tmp/TP01/sample/ with the abolute way and rename the target file to MyHostName
-
Try to copy with the cp command the direcrtory /tmp/TP01/sample/ into your /home/isen/Notes/C01/ directory. What is the message
-
Find in the man of cp the way to copy directory and the verbose option and retry.
The rm / rmdir commands
-
With the rm command, delete the file /tmp/TP01/sample/MyFirstFile
-
With the rm command, try to delete the directory /tmp/TP01/sample/
-
Find in the man of rm the way to delete directories and files recursively.
The mv command
-
With the mv command, move the file /home/isen/Notes/C01/sample/MyHostName into /home/isen/Notes/C01/ with the abolute way
-
With the mv command, move the file /home/isen/Notes/C01/MyHostName into /home/isen/Notes/C01/sample/ with the abolute way and rename the target file to HostName
The file command
Wwith the file command check the file type of :
- /
- /home/isen
- /home/isen/Notes/C01/MyFirstFile
- /usr/bin/uptime
- /etc/init.d/ssh
File Permission
Files Rights
with the ls command and the option -l -d print the right of /home/isen/Notes/C01
-
find in the man what is the -d option
-
who is the owner ?
-
what is the group ?
-
Explain what is the read access for a directory
-
Explain what is the write access for a directory
-
Explain what is the execute access for a directory
-
Is anybody can read the contain of the directory ? (other)
with the ls command and the option -l print the right of /home/isen/Notes/C01/MyFirstFile
-
who is the owner ?
-
what is the group ?
-
Explain what is the read access for a file
-
Explain what is the write access for a file
-
Explain what is the execute access for a file
-
Is anybody can read the contain of the file ? (other)
The grep command
The grep command searches for PATTERNS in each FILE.
With the command grep find the string DEFAULT_HOME in the file /etc/login.defs
UMASK
The UMASK determines the settings of a mask that controls how file permissions are set for newly created files.
-
to get current UMASk : umask
-
convert the right of /home/isen/Notes/C01/MyFirstFile in octal mode
-
Analyse the octal mode and the UMASK we find.
The chmod command
octal chmod
- With ls -l print the right of /home/isen/Notes/C01/MyFirstFile
Change with the chmod command in octal mode the right of /home/isen/Notes/C01/MyFirstFile to :
- owner : all right
- group : nothing
- other : nothing
letter chmod
- With ls -l print the right of /home/isen/Notes/C01/MyFirstFile
Change with the chmod command in letter mode the right of /home/isen/Notes/C01/MyFirstFile to :
- owner : delete the execution right
- group : no change
-
other : no change
-
With ls -l print the right of /home/isen/Notes/C01/MyFirstFile
Change with the chmod command in letter mode the right of /home/isen/Notes/C01/MyFirstFile to :
- owner : add execution right
- group : add read and write right
-
other : delete all right
-
With ls -l print the right of /home/isen/Notes/C01/MyFirstFile
-
What will be the octal syntax for the last letter change
root
sudo
Some commands can only be used by the root user
Usually the root access is secured. Here, we have voluntarily facilitated access to this account for the purposes of practical work.
The user isen is allowed to used sudo like root without passwd
BE CAREFUL !!! BE CAREFUL !!! BE CAREFUL !!!
the sudo command allow you to do command in substituion of another user (Swith User DO)
-
type and explain the command whoami
-
with the command sudo, execute the command whoami from isen
-
with the command sudo, execute the command touch /tmp/TestFile from isen
-
with the command ls -l what are the rights of the file /tmp/TestFile
For the connection from isen you have to do this command :
isen@name_s_client ~ $ sudo su - root
- Once logged in, what directory are you in? Why ?
root disconnection
You can disconnect from the root account with the exit command or with the key combination : "CTRL+D"
passwd
-
with the command passwd change the password of isen with the isen account
-
with the command passwd change the password of isen with the root account
-
with the command passwd change the password of root with the root account
su
-
with the su command without sudo, connect to the root account from isen
-
Once logged in, what directory are you in? Why ?
-
with the su - root command without sudo, connect to the root account from isen
-
Once logged in, what directory are you in? Why ?
root connection environement
isen@name_s_client ~ $ sudo su
- Once logged in, what directory are you in? Why ?
isen@name_s_client ~ $ sudo su root
- Once logged in, what directory are you in? Why ?
root@name_s_client ~ # su isen
- Once logged in, what directory are you in? Why ?
root@name_s_client ~ # su - isen
- Once logged in, what directory are you in? Why ?
User
cat command
The cat command concatenate files and print on the standard output
-
With the cat command and the /etc/passwd file, are there other accounts on this machine?
-
Withe the grep command and the /etc/passwd file How to list all the accounts who can connect ?
-
With the cat command and the file /etc/shadow, how many users can login using a password?
useradd command
The useradd command can create user with CLI.
-
Create an eleve1 account with the command and define a password for it.
-
Connect with this user, what do you notice?
-
In root, create the home directory of eleve1 with the commands mkdir and chown
-
Create a new eleve2 account in order to automatically create your home directory.
-
Compare the contents of the eleve1 and eleve2 user directories. (don't forget to print the hiddens files)
-
Now compare with the contents of the /etc/skel directory.
-
Create a new eleve3 account in order to automatically create your home directory and the shell of connection.
-
read in the terminal the /etc/passwd file and compare the line with eleve1,2,3
Group management
-
To which groups do the "eleve1" and "eleve2" accounts belong?
-
With the groupadd command, create an "eleves" group with a GID equal to 600.
-
Create a group "teachers" with a GID of 700.
-
By modifying the appropriate file, put the group "eleves" in the primary group of the user "eleve1". You have to use the command micro
micro is a simple terminal text editor
to have some help type : micro --help
to save and quit a file you are editing use the key combination :
[ALT+s]
-
Using the "usermod" command, do the same for the "eleve2" user.
-
With the command groupdel, delete the groups "eleve1" and "eleve2".
-
Create an account "prof1" having as primary group "teachers" and as secondary group "eleves".
-
Using the "usermod" command, do add isen in the list of supplementary groups (be carreful to NOT change the initial login group)
-
Verify with the id command the user isen
The chown command
-
as isen, create a directory in /home/isen/Notes/C01/DirTest
-
With the command chown (in root) change the owner of /home/isen/Notes/C01/DirTest to eleve1
-
With the command su, connect isen user and try to get in /home/isen/Notes/C01/DirTest :
-
are you allow to enter the directory ? Why
-
are you allow to create a file in the directory ? Why
-
With the command chmod (in root) change the right of /home/isen/Notes/C01/DirTest to 700
-
With the command su, connect isen user and try to get in /home/isen/Notes/C01/DirTest :
-
are you allow to enter the directory ? Why
-
are you allow to create a file in the directory ? Why
The chgrp command
-
during the creation of the user eleve1, we changed is group to eleves but the directory /home/eleve1 we create always have the group eleve1. But we delete it. With the command ls -ld, print the owner and group of /home/eleve1. What do you obseved ?
-
Modify the owner group of the /home/eleve1 directories accordingly to the modification made in the file /etc/passwd
-
With the command chgrp (in root) change the group of /home/isen/Notes/C01/DirTest to eleves
-
With the command chmod (in root) change the right of /home/isen/Notes/C01/DirTest to 770
With the command su, connect isen user and try to get in /home/isen/Notes/C01/DirTest :
-
are you allow to enter the directory ? Why
-
are you allow to create a file ? Why
-
With the command chmod (in root) change the right of /home/isen/Notes/C01/DirTest to 700
With the command su, connect isen user and try to get in /home/isen/Notes/C01/DirTest :
-
are you allow to enter the directory ? Why
-
are you allow to create a file ? Why