Understand and use essential tools Flashcards
Objective 1 for exam
Virtual Console or tty
Ctrl + alt + F1 through F6. Ctlr + alt+ F7 will bring back the GUI
cat example
cat «_space;EOF > file1
> this is the content
> of file 1
> EOF
cat example 2
cat > file1 this is the content of file1 ^d ^d(ctrl+d stop entry)
grep examples
grep –color ‘root’ /etc/passwd
grep -i ‘root’ /etc/passwd matches case insensitive
grep -v ‘root’ /etc/passwd matches everything but root
grep -n [Aa] text.txt matches upper and lower case
grep ‘^root’ /etc/passwd starts with root
grep ‘root$’ /etc/passwd end with root
generate ssh key
use the ssh-keygen command
create a tarball example
tar -cvf data.tar dataDir
gzip tar file/directory
gzip data.tar creates data.tar.gz
bzip tar file/directory
bzip data.tar creates data.tar.bz2
tar with gzip file/directory
tar -czvf data.tar.gz dataDir
tar -czvf data.tgz dataDir
tar with bzip2 file/directory
tar -cjvf data.tar.bz2 dataDir
extract tar.gz
tar -xzvf data.tar.gz
extract tar.bz2
tar -xjvf data.tar.bz2
Main Tar command options
c(create an archive), x(extract an archive), t(test or list the contents of an archive)
Other tar command options
v(verbosity), f(filename), z(for gzip), j(for bzip2)
bzip to uncompress files
bunzip abc.tar.bz2
gzip to uncompress files
gunzip2 etc.tgz
Star command
More appropriate for archiving files in a SELinux System. It's not installed by default: # yum install star
Star command to archive a file
star -xattr -H=exustar -c -f=home.star /home
star more example to compress a file/directory(ies)
star -cv f=archive2.star test-dir
star -xattr -H=exustar -c -f=files.star file{1,2,3}
Star extract file/directory(s) example
star -xv f=/tmp/archive2.star
star list files in an archive file
star -tv f=/tmp/archive2.star
Text editors
Vi(Preferred)
gedit(GUI)
nano(text editor)
Create a hard link
ln filetolink desktop/file
Create a symlink
ln -s filetolink desktop/filelink
To view inode #
ls -li file
Hard link
a pointer to a file’s inode
soft link (symlink)
a pointer to a file
Linux ugo/rwx permissions
read (r)
write(w)
execute(x)
Octal value for permission bit
read = 4 write = 2 execute = 1 No permission(or dash "-") = 0
Umask command
The default permission in RHEL comes from the umask or user file creation mode mask value. run the umask command to see your default umask value: # umask
Umask value obtained
From the /etc/profile script
File default umask
666
Directory default umask
777
Calculate umask of a file
subtract default file umask (666) from current user’s umask(0022) = 0644
Calculate umask of a directory
subtract default directory umask(777) from current user’s umask(0022) = 0755
set the immutable bit
chattr +i file
view attributes of a file
lsattr file
immutable bit
It helps prevent accidental deletion. Review man 1 chattr to learn more attributes which can be applied to a file
attributes that can be added to a file
(acdeijstuADST), a = append only, c = compressed, d = no dump, e = extent format, i = immutable, j = data jornaling, s = secure deletion, t=no-tail-merging, u = undeletable, A = no atime updates, D = synchronous directory updates, S= synchronous updates, T = top of directory hierarchy.
chattr options
- R = recursively
- V = verbose
- f = suppress most error messages
- v = set the file version(generation number)
Managing Permissions from gui
You can use the Nautilus file management tool
– right click on a file or folder > select properties > click on the permission Tab.
– Or launch Nautilus from the command line:
# Nautilus &
Special permissions
Setuid or setgid permission of an executable means that the command will run as the user(or group) of the file, not as the user that ran it.
The sticky bit for a directory sets a special restriction on deletion of files: only the owner of the file and root can delete within the directory, example is /tmp
special permissions effect on files
U+s (SUID) - file executes as the user that owns the file, not the user that ran the file.
G+s(SGID) - file executes as the group that owns the file.
o+t(sticky) - no effect on file
Special permissions effect on directories
U+s(SUID) - no effect on directory
G+s(SGID) - files newly created in the directory have their group owner set to match the group owner of the directory.
O+t(sticky) - users with write on the directory can only remove files that they own, they cannot remove files owned by other users
Setting special permissions
Symbolically: setuid = u+s, setgid = g+s, sticky = o+t Numerically: (fourth preceding digit) setuid = 4; setgid = 2; sticky = 1. # chmod 4770 file # chmod 2770 dir # chmod g+s dir
to search for unknown man pages
# man -k lvm # apropos lvm # whatis nfs or you can run ls on /usr/share/doc
no output from man pages
First check for the package # rpm -qa man then if it's installed run: # makewhatis &
info pages
Similar to man pages, also over
# info -k lvm
info pages are located in /usr/share/info
Man pages sections and meanings
1 ———– user commands
2 ———- Kernel System calls (entry points to the kernel from userspace)
3 ———- Library functions
4 ———- Special files and devices
5 ———- file formats and conventions
6 ———- Games
7 ———- Conventions, standard, and miscellaneous pages
8 ———- System administration commands
9 ———- Linux kernel HPI (internal kernel calls), this is recent
Access remote system using VNC
$ yum install tigervnc-server </code>
This puts a config file on your remote machine in /etc/sysconfig/vncservers
edit this file and add:
VNCSERVERS=”2:myusername”
VNCSERVERARGS[2]=”-geometry 800x600 -nolisten tcp -nohttpd”
Aside from changing “username” you want it to look like this. All we did to change it, is remove the “-localhost” directive. This would have restricted us from connecting from a remote system without a tunnel setup. Since this is an exam and not the real world, we can disable that.
Set up your password on the remote machine by running
$ vncpasswd</code>
And finally start your vncserver
$ vncserver :1</code>
The output should look like this:
[root@rhel6 ~]# vncserver :1
New ‘rhel6.local:1 (root)’ desktop is rhel6.local:1<br></br>
Starting applications specified in /root/.vnc/xstartup<br></br>
Log file is /root/.vnc/rhel6.local:1.log
The default vnc client on Red Hat Enterprise Linux 6 is tigervnc. If it is not already installed on the system:
$ yum install tigervnc</code>
To connect to the newly setup vncserver just type:
$ vncviewer rhel6.local:5901
(replace rhel6.local with your remote host)
create SSH Keys and change permissions(example)
$sudo su - username $ cd .ssh $ssh-keygen -t rsa $cat id_rsa.pub > authorized_keys $cp id_rsa authorized_hosts $chmod 644 $HOME/.ssh/authorized_hosts $chmod 700 $HOME/.ssh
Test
$ssh host