Linux Notes
Linux Notes
Linux Notes
The examples in this document assume that you are using a POSIX-compliant (such as bash, sh, zsh, ksh)
shell.
Large portions of GNU/Linux functionality are achieved using the terminal. Most distributions of Linux include
terminal emulators that allow users to interact with a shell from their desktop environment. A shell is a command-
line interpreter that executes user inputted commands. Bash (Bourne Again SHell) is a common default shell
among many Linux distributions and is the default shell for macOS.
These shortcuts will work if you are using Bash with the emacs keybindings (set by default):
Open terminal
Cursor movement
Ctrl + A Go to the beginning of the line you are currently typing on.
Ctrl + E Go to the end of the line you are currently typing on.
Ctrl + XX Move between the beginning of the line and the current position of the cursor.
Alt + F Move cursor forward one word on the current line.
Alt + B Move cursor backward one word on the current line.
Ctrl + F Move cursor forward one character on the current line.
Ctrl + B Move cursor backward one character on the current line.
Text manipulation
Ctrl + U Cut the line from the current position to the beginning of the line, adding it to the clipboard. If
you are at the end of the line, cut the entire line.
Ctrl + K Cut the line from the current position to the end of the line, adding it to the clipboard. If you
are at the beginning of the line, cut the entire line.
Ctrl + W Delete the word before the cursor, adding it to the clipboard.
Ctrl + Y Paste the last thing from the clipboard that you cut recently (undo the last delete at the
current cursor position).
Alt + T Swap the last two words before the cursor.
Alt + L Make lowercase from cursor to end of word.
Alt + U Make uppercase from cursor to end of word.
Alt + C Capitalize to end of word starting at cursor (whole word if cursor is at the beginning of word).
Alt + D Delete to end of word starting at cursor (whole word if cursor is at the beginning of word).
Alt + . Prints the last word written in previous command.
Ctrl + T Swap the last two characters before the cursor.
History access
Terminal control
Special characters
Close Terminal
Alternatively, you can switch to the vi keybindings in bash using set -o vi. Use set -o emacs to switch back to the
emacs keybindings.
Whenever you are in a terminal in Linux, you will be in what is called the current working directory. Often your
command prompt will display either the full working directory, or just the last part of that directory. Your prompt
could look like one of the following:
user@host ~/somedir $
user@host somedir $
user@host /home/user/somedir $
Therefore, if the current directory is /home/user/somedir, then cd ../somedir will not change the working
directory.
The table below lists some of the most used file management commands
Directory navigation
Command Utility
pwd Get the full path of the current working directory.
cd - Navigate to the last directory you were working in.
cd ~ or just cd Navigate to the current user's home directory.
cd .. Go to the parent directory of current directory (mind the space between cd and ..)
Listing files inside a directory
Command Utility
List the files and directories in the current directory in long (table) format (It is recommended to
ls -l
use -l with ls for better readability).
ls -ld dir-name List information about the directory dir-name instead of its contents.
ls -a List all the files including the hidden ones (File names starting with a . are hidden files in Linux).
Appends a symbol at the end of a file name to indicate its type (* means executable, / means
ls -F
directory, @ means symbolic link, = means socket, | means named pipe, > means door).
List the files sorted by last modified time with most recently modified files showing at the top
ls -lt
(remember -l option provides the long format which has better readability).
ls -lh List the file sizes in human readable format.
ls -lR Shows all subdirectories recursively.
tree Will generate a tree representation of the file system starting from the current directory.
File/directory create, copy and remove
Command Utility
Will copy the file from source to destination. -p stands for preservation. It
cp -p source destination preserves the original attributes of file while copying like file owner, timestamp,
group, permissions etc.
cp -R source_dir
destination_dir
Will copy source directory to specified destination recursively.
Hello World
Command Usability
man <name> Read the manual page of <name>.
man <section> <name> Read the manual page of <name>, related to the given section.
man -k <editor> Output all the software whose man pages contain <editor> keyword.
man -K <keyword> Outputs all man pages containing <keyword> within them.
Output all the applications whose one line description matches the word editor.
apropos <editor>
When not able to recall the name of the application, use this command.
help In Bash shell, this will display the list of all available bash commands.
help <name> In Bash shell, this will display the info about the <name> bash command.
info <name> View all the information about <name>.
dpkg -l Output a list of all installed packages on a Debian-based system.
dpkg -L packageName Will list out the files installed and path details for a given package on Debian.
dpkg -l | grep -i <edit> Return all .deb installed packages with <edit> irrespective of cases.
less /var/lib/dpkg/available Return descriptions of all available packages.
whatis vim List a one-line description of vim.
Display usage information about the <tool-name>. Sometimes command -h also
<command-name> --help
works, but not for all commands.
Command Usability
hostname Display hostname of the system.
Command Usability
List all processes sorted by their current system resource usage. Displays a continually updated
top
display of processes (By default 3 seconds). Use q key to exit top.
ps List processes currently running on current shell session
ps -u root List all of the processes and commands root is running
ps aux List all the processes by all users on the current system
This will print out the full path/filename to all files under /var/www that end in .css. Example output:
/var/www/html/text-cursor.css
/var/www/html/style.css
man find
This will print all lines containing the pattern font in the specified file. Example output:
font-weight: bold;
font-family: monospace;
Another example:
Notice that when grep is matching multiple files, it prefixes the matched lines with the filenames. You can use the -
h option to get rid of that, if you want.
man grep
touch myFile
mv myFile myFirstFile
cat myFirstFile
less myFirstFile
head myFirstFile
tail myFirstFile
Edit a file:
ls
mkdir myFirstDirectory
Create multi path directory: (creates two directories, src and myFirstDirectory)
mkdir -p src/myFirstDirectory
mv myFirstFile myFirstDirectory/
cd myFirstDirectory
Delete a file:
rm myFirstFile
cd ..
rmdir myFirstDirectory
rm -rf myFirstDirectory
Make note that when deleting directories, that you delete ./ not / that will wipe your whole filesystem.
Details/Rights
The l option shows the file permissions, size, and last modified date. So if the root directory contained a dir called
test and a file someFile the command:
The permissions are in format of drwxrwxrwx. The first character represents the file type d if it's a directory -
otherwise. The next three rwx are the permissions the user has over the file, the next three are the permissions the
group has over the file, and the last three are the permissions everyone else has over the file.
The r of rwx stands for if a file can be read, the w represents if the file can be modified, and the x stands for if the
file can be executed. If any permission isn't granted a - will be in place of r, w, or x.
So from above user can read and modify someFile.txt but the group has only read-only rights.
To change rights you can use the chmod ### fileName command if you have sudo rights. r is represented by a
value of 4, w is represented by 2, and x is represented by a 1. So if only you want to be able to modify the contents
to the test directory
Readable Size
Used in conjunction with the l option the h option shows file sizes that are human readable. Running
user@linux-computer:~$ ls -lh
Would output:
total 4166
-rw-r--r-- 1 user users 70 Jul 22 13:36 someFile.txt
drwxrwxrwx 2 user users 4.0K Jul 21 07:18 test
Hidden
user@linux-computer:~$ ls -a
Might list
To view the size of the current directory use the s option (the h option can also be used to make the size more
readable).
user@linux-computer:~$ ls -s
Outputs
total 4166
someFile.txt test
Recursive View
Lets say test directory had a file anotherFile and you wanted to see it from the root folder, you could use the R
option which would list the recursive tree.
user@linux-computer:~$ ls -R
Outputs
.:
someFile.txt test
./test:
anotherFile
On Debian:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux testing (stretch)
Release: testing
Codename: stretch
On Ubuntu:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.4 LTS
Release: 14.04
Codename: trusty
In case when you don't have lsb_release installed you may want to try some guessing, for example, there is a file
/etc/issue that often contains distribution name. For example, on ubuntu:
$ cat /etc/issue
Ubuntu 12.04.5 LTS \n \l
Don't use file /etc/debian_version because its contents do not match distribution name!
Note that this will also work on non-Debian-family distributions like Fedora, RHEL, or openSUSE — but that lsb_release
may not be installed.
Look at /etc/os-release. In specific, look at variables NAME, VERSION, ID, VERSION_ID, and PRETTY_NAME.
NAME=Fedora
VERSION="24 (Workstation Edition)"
ID=fedora
VERSION_ID=24
PRETTY_NAME="Fedora 24 (Workstation Edition)"
ANSI_COLOR="0;34"
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
This file is documented on the freedesktop web site; in principle, it is not systemd specific — but it will exist on all
systemd-based distributions.
From the bash shell, one can source the /etc/os-release file and then use the various variables directly, like this:
cat /etc/redhat-release
Here is the output from a Fedora 24 machine: Fedora release 24 (Twenty Four)
As mentioned in the debian-based response, you can also use the lsb_release -a command, which outputs this
from a Fedora 24 machine:
uname [OPTION]
Example:
> uname -a
On Arch:
$ uname -a
Linux nokia 4.6.4-1-ARCH #1 SMP PREEMPT Mon Jul 11 19:12:32 CEST 2016 x86_64 GNU/Linuxenter
code here
If you do not know what system you are using you may not be able to directly jump to one of the examples above,
hence this may be your first port of call.
$ uname -a
I would welcome any others to add in results for RHEL, and SuSe systems.
Section 2.7: Find your linux os (both debian & rpm) name and
release number
Most of linux distros stores its version info in the /etc/lsb-release (debian) or /etc/redhat-release (RPM based) file.
Using below generic command should get you past most of the Debian and RPM derivatives as Linux Mint and
Cent-Os.
cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"
uname -a
Linux df1-ws-5084 4.4.0-64-generic #85-Ubuntu SMP Mon Feb 20 11:50:30 UTC 2017 x86_64
x86_64 x86_64 GNU/Linux
The command (actually an executable binary, an ELF) that is responsible for changing shells in Linux is chsh (change
shell).
We can first check which shells are already installed and configured on our machine by using the chsh -l
command, which will output a result similar to this:
In some Linux distributions, chsh -l is invalid. In this case, the list of all available shells can be found at /etc/shells
file. You can show the file contents with cat:
Now we can choose our new default shell, e.g. fish, and configure it by using chsh -s,
Now all that is left to do is preform a logoff-logon cycle, and enjoy our new default shell.
If you wish to change the default shell for a different user, and you have administrative privileges on the machine,
you'll be able to accomplish this by using chsh as root. So assuming we want to change user_2's default shell to
fish, we will use the same command as before, but with the addition of the other user's username, chsh -s
/usr/bin/fish user_2.
In order to check what the current default shell is, we can view the $SHELL environment variable, which points to
the path to our default shell, so after our change, we would expect to get a result similar to this,
chsh options:
-s shell
-l, --list-shells
-h, --help
-v, --version
Default command prompt can be changed to look different and short. In case the current directory is long default
command prompt becomes too large. Using PS1 becomes useful in these cases. A short and customized command
pretty and elegant. In the table below PS1 has been used with a number of arguments to show different forms of
shell prompts. Default command prompt looks something like this: user@host ~ $ in my case it looks like this:
bruce@gotham ~ $. It can changed as per the table below:
Command Utility
PS1='\w $ ' ~ $ shell prompt as directory name. In this case root directory is Root.
PS1='\h $ ' gotham $ shell prompt as hostname
PS1='\u $ ' bruce $ shell prompt as username
PS1='\t $ ' 22:37:31 $ shell prompt in 24 hour format
PS1='@ $ ' 10:37 PM shell prompt in 12 hour time format
PS1='! $ ' 732 will show the history number of command in place of shell prompt
PS1='dude $ ' dude $ will show the shell prompt the way you like
Some basic shell commands
Command Utility
Ctrl-k cut/kill
Ctrl-y yank/paste
Ctrl-a will take cursor to the start of the line
Ctrl-e will take cursor to the end of the line
Ctrl-d will delete the character after/at the cursor
Ctrl-l will clear the screen/terminal
Ctrl-u will clear everything between prompt and the cursor
Ctrl-_ will undo the last thing typed on the command line
Ctrl-c will interrupt/stop the job/process running in the foreground
The best way to do this is to modify (or create if it does not exist) a file called .bash_aliases in your home folder. The
general syntax is:
alias command_alias='actual_command'
where actual_command is the command you are renaming and command_alias is the new name you have given it.
For example
maps the new command alias install to the actual command sudo apt-get -y install. This means that when
you use install in a terminal this is interpreted by bash as sudo apt-get -y install.
locate mykey.pem
Sometimes files have strange names for example you might have a file like random7897_mykey_0fidw.pem. Let's say
you're looking for this file but you only remember the mykey and pem parts. You could combine the locate
command with grep using a pipe like this:
Which would bring up all results which contain both of these pieces.
Note that not all systems have the locate utility installed, and many that do have not enabled it. locate is fast and
efficient because it periodically scans your system and caches the names and locations for every file on it, but if that
data collection is not enabled then it cannot tell you anything. You can use updatedb to manually initiate the
filesystem scan in order to update the cached info about files on your filesystem.
Should you not have a working locate, you can fall back on the find utility:
is roughly equivalent to locate mykey.pem but has to scan your filesystem(s) each time you run it for the file in
question, rather than using cached data. This is obviously slower and less efficient, but more real-time. The find
utility can do much more than find files, but a full description of its capabilities is beyond the scope of this example.
du:
du command summarizes disk usage of the set of FILEs, recursively for directories.
-s, --summarize
display only a total for each argument
-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
For summarizing disk usages of the files in the current directory we use:
du -sh *
Example output:
572K Documents
208M Downloads
4,0K Music
724K Pictures
4,0K Public
4,0K Templates
4,0K Videos
du -sh .[!.]* *
Example output:
6,3M .atom
4,0K .bash_history
4,0K .bash_logout
8,0K .bashrc
350M .cache
195M .config
12K .dbus
4,0K .dmrc
44K .gconf
60K .gem
520K .gimp-2.8
28K .gnome
4,0K .ICEauthority
8,3M .local
8,0K .nano
404K .nv
36K .pki
Thirdly, you can add total to the output by adding ,-c, option:
du -sch .[!.]* *
Result:
.
.
.
4,0K Templates
4,0K Videos
769M total
Most importantly using du command properly on the root directory is a life saving action to find out what
application/service or user is consuming your disk space wildly. For example, in case of a ridiculously low level of
disk space availability for a web and mail server, the reason could be a spam attack to your mail service and you
can diagnose it just by using du command.
Example output:
16K /.VolumeIcon.icns
24K /.VolumeIcon.png
13M /bin
57M /boot
4,0K /cdrom
620K /dev
13M /etc
779M /home
0 /initrd.img
406M /lib
3,9M /lib32
4,0K /lib64
16K /lost+found
4,0K /media
4,0K /mnt
367M /opt
du: cannot access '/proc/18221/task/18221/fd/4': No such file or directory
du: cannot access '/proc/18221/task/18221/fdinfo/4': No such file or directory
du: cannot access '/proc/18221/fd/4': No such file or directory
Lastly, the best method forms when you add a threshold size value for directories to ignore small ones. This
command will only show folders with more than 1GB in size which located under root directory up to the
farthermost branch of the whole directory tree in your file system:
Example output:
1,4G /usr/lib
1,8G /usr/share
3,5G /usr
5,8G total
df -h
[root@mail ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
19G 1.6G 16G 9% /
tmpfs 245M 0 245M 0% /dev/shm
/dev/sda1 485M 47M 413M 11% /boot
In this basic example, we can see that the / partition only has 9% used.
For a more complex example that also covers using df to see various mountpoints, see below:
[root@mail ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VG-root 1.9T 1.7T 89G 95% /
/dev/mapper/VG-var 431G 145G 264G 36% /var
devtmpfs 7.8G 204K 7.8G 1% /dev
tmpfs 7.8G 4.0K 7.8G 1% /dev/shm
/dev/md1 495M 126M 344M 27% /boot
ku.example.com:9421 2.5T 487G 2.0T 20% /mnt/test
tmpfs 500M 86M 415M 18% /var/ngx_pagespeed_cache
It's got an external network mount of 2T that's mounted on /mnt/test and a ramdisk/tmpfs mount of 500M
mounted on /var/ngx_pagespeed_cache.
CPU
To get processors related statistics you can use mpstat command but with some options it will provide better
visibility:
$ mpstat 2 10
Memory
We all know command free to show amount of (remaining) RAM but to see all statistic including I/O operations:
$ vmstat 2 10
Disk
To get general information about your disk operations in real time you can utilise iostat.
$ iostat -kx 2
Network
To be able to see what is happening with your network services you can use netstat
But you can find useful monitoring to see network traffic in real time:
$ sudo iftop
Optional
To generate statistics in real time related to I/O operations across all components you can use dstat. That tool that
is a versatile replacement for vmstat, iostat and ifstat
$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
df1-ws-5084
description: Computer
width: 64 bits
capabilities: vsyscall32
*-core
description: Motherboard
physical id: 0
*-memory
description: System memory
physical id: 0
size: 5881MiB
*-cpu
product: Intel(R) Pentium(R) CPU G3220 @ 3.00GHz
vendor: Intel Corp.
physical id: 1
bus info: cpu@0
size: 3GHz
capacity: 3GHz
width: 64 bits
lshw is a small tool to extract detailed information on the hardware configuration of the machine. It can report
exact memory configuration, firmware version, mainboard configuration, CPU version and speed, cache
configuration, bus speed, etc.
$ lspci -tv
$ lsusb -tv
$ dmidecode -q | less
To see specific information about disk (disk sda in example) you can use:
$ hdparm -i /dev/sda
$ smartctl -A /dev/sda | grep Power_On_Hours # How long has this disk (system) been powered on in
total
$ hdparm -tT /dev/sda # Do a read speed test on disk sda
$ badblocks -s /dev/sda # Test for unreadable blocks on disk sda
$ cat /proc/cpuinfo
Sample Output:
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz
stepping : 11
cpu MHz : 1596.000
cache size : 4096 KB
physical id : 0
siblings : 4
core id : 0
cpu cores : 4
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts
acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good pni
dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm lahf_lm tpr_shadow vnmi flexpriority
bogomips : 4800.18
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
....
..
processor : 3
vendor_id : GenuineIntel
cpu family : 6
Static monitoring
Most widely used command is ps (i.e., process status) command is used to provide information about the currently
running processes, including their process identification numbers (PIDs).
$ ps -e -o pid,args --forest
$ ps -C firefox-bin -L -o pid,tid,pcpu,state
After finding specific process you can gather information related to it using lsof to list paths that process id has
open
Or based on path find out list processes that have specified path open
$ lsof ~
Interactive monitoring
$ top
That mostly default command that have huge amount options to filter and represent information in real time (in
comparison to ps command.
Still there are more advance options that can be considered and installed as top replacement
$ htop -d 5
or
$ atop
Which has ability to log all the activities into log file (default atop will log all the activity on every 600 seconds) To this
list there are few specialised commands as iotop or iftop
$ sudo iotop
user@ubuntu14:/usr$ ls
bin games include lib lib32 local sbin share src
user@ubuntu14:/usr$ ls -a
. .. bin games include lib lib32 local sbin share src
To differentiate between files and folders and symbolic links and other, use ls -F OR ls --classify
user@ubuntu14:~$ ls -F
bash_profile_course chat_apps/ Desktop/ Downloads/ foxitsoftware/
Public/ test/ bin/ ClionProjects/ Documents/ IDE/ Music/
Pictures/ Templates/ Videos/
“*”suggest executables.
user@ubuntu14:~/example$ ls -l
total 6464
Then there is an entry for each file/directory in alphabetical order with upper case before lower case.
The next 9 characters show the permissions for the user, group and other.
This is followed by the number of hard links, then the owner's name and group.
The next field is the size in bytes. This can be displayed in a human friendly form by adding the -h option e.g.
6586816 is displayed as 6.3M
The final field is the name. Note: links also show the target of the link.
Verbose output shows which files and directories are added to the archive, use the -v option:
For archiving a folder compressed 'gzip', you have to use the -z option :
You can instead compress the archive with 'bzip2', by using the -j option:
The option -t is used for the listing. For listing the content of a tar.gz archive, you have to use the -z option
anymore :
my-folder/
sub1/
sub2/
sub3/
./archive.tar
my-folder/
sub2/
--strip-components=NUMBER
strip NUMBER leading components from file names on extraction
service --status-all
The output of service --status-all lists the state of services controlled by System V.
The + indicates the service is running, - indicates a stopped service. You can see this by running service
SERVICENAME status for a + and - service.
Some services are managed by Upstart. You can check the status of all Upstart services with sudo initctl list. Any
service managed by Upstart will also show in the list provided by service --status-all but will be marked with a ?.
ref: https://askubuntu.com/questions/407075/how-to-read-service-status-all-results
Masking services
systemctl mask [service-name] To mask a service (Makes it hard to start a service by mistake)
systemctl unmask [service-name] To unmask a service
Restarting systemd
systemctl daemon-reload
...where [servicename] is the service in question; for example, systemctl status sshd.
This will show basic status information and any recent errors logged.
You can see further errors with journalctl. For example,journalctl -xe will load the last 1000 logged into a pager
(like less), jumping to the end. You can also use journalctl -f, which will follow log messages as they come in.
To see logs for a particular service, use the -t flag, like this:
journalctl -f -t sshd
Other handy options include -p for priority (-p warnings to see only warnings and above), -b for "since last boot",
and -S for "since" — putting that together, we might do
If journalctl is not available, or if you are following application error logs which do not use the system journal, the
tail command can be used to show the last few lines of a file. A useful flag for tail is -f (for "follow"), which causes
tail continue showing data as it gets appended to the file. To see messages from most services on the system:
tail -f /var/log/messages
tail -f /var/log/secure
Some services have their own log files, a good example is auditd, the linux auditing daemon, which has its logs
stored in /var/log/audit/. If you do not see output from your service in /var/log/messages try looking for service
specific logs in /var/log/
On systems using systemd, such as Ubuntu (Server and Desktop) >= 15.04, and RHEL/CentOS >= 7:
On systems using systemd, such as Ubuntu (Server and Desktop) >= 15.04, and RHEL/CentOS >= 7.0:
passwd username
useradd username
userdel username
userdel -r username
More detailed information about user and group numerical IDs can be found with the id command.
More detailed information about user and group numerical IDs can be found with id username.
LAMP is used as a Open Source stack of technologies solution to web development area. Windows version of this
stack is called WAMP (Windows Apache MySQL PHP)
HTTP
Edit
/etc/httpd/conf/httpd.conf
The folder of the WEB Pages by default is ServerRoot "/etc/httpd". Directory must be set to the same folder, so
change the line
<Directory "/etc/httpd">
Now you need the ~/public_html folder for each user. (to get the root page of each user as
http://localhost/~yourusername/. Unremark this line:
Include conf/extra/httpd-userdir.conf
Now as root you need to create the ~/public_html for each user and change the access to (755) of each one.
You can comment out this line if you want to use SSL:
Include conf/extra/httpd-vhosts.conf
and in /etc/httpd/conf/extra/httpd-vhosts.conf you must to add all the virtual domains. (plus into /etc/hosts
if you want to test those virtuals domains)
PHP
Edit: /etc/httpd/conf/httpd.conf
Edit /etc/php/php.ini
MySQL
Run as root:
At last, run:
sh /usr/bin/mysql_secure_installation
Install MySql:
Install PHP:
Restart system:
Once it is installed, enable (to run on startup) and start Apache web server service.
http://localhost
Install PHP
http://localhost/index.php
You should see information related to your server. If you do not, ensure that php is for sure installed correctly by
running the following command:
php --version
PHP 5.4.16 (cli) (built: Nov 6 2016 00:29:02) Copyright (c) 1997-2013 The PHP Group
Then PHP is installed correctly. If this is the case, please ensure that you've restarted your web server.
tee - read from standard input and write to standard output and files.
The tee command is named after the T-splitter in plumbing, which splits water into two directions and is shaped like
an uppercase T.
tee copies data from standard input to each FILE, and also to standard output. In effect, tee duplicates its input,
routing it to multiple outputs at once.
$ ls
The following command writes the output only to the file and not to the screen.
$ ls > file
The following command (with the help of tee command) writes the output both to the screen (stdout) and to the
file.
$ ls | tee file
The following command will write current crontab entries to a file crontab-backup.txt and pass the crontab
entries to sed command, which will do the substituion. After the substitution, it will be added as a new cron job.
$ ls | tee –a file
port - The listening ssh port of the server (default port 22).
user - Must be an existing user on the server with SSH privileges.
server address - The IP/Domain of the server.
For a real world example lets pretend that you're making a website. The company you chose to host your site tells
you that the server is located at web-servers.com on a custom port of 2020 and your account name usr1 has been
chosen to create a user on the server with SSH privileges. In this case the SSH command used would be as such
If account name on the remote system is the same as the one one the local client you may leave the user name off.
So if you are usr1 on both systems then you my simply use web-servers.com instead of [email protected].
When a server you want to connect to is not directly accessible to you, you can try using ProxyJump switch to
connect to it through another server which is accessible to you and can connect to the desired server.
This will let you connect to the server 10.0.0.2 (running ssh on port 2222) through server at 10.0.0.1 (running ssh on
port 2020). You will need to have accounts on both servers of course. Also note that the -J switch is introduced in
OpenSSH version 7.3.
Debian:
Arch Linux:
# pacman -S openssh
Yum:
Use your text editor to change the values set in this file, all lines starting with # are commented out and must have
this character removed to take any effect. A list of recommendations follow as such.
Port (chose a number between 0 - 65535, normaly greater than four digits)
PasswordAuthentication yes
AllowUsers user1 user2 ...etc
Note that it is preferable to disable password logins all together and use SSH Keys for improved security as explained in
this document.
Your key pair is composed by a private key (id_rsa) and a public key (id_rsa.pub). All you need to do is to copy the
public key to the remote host and add its contents to the ~/.ssh/authorized_keys file.
Once the public key is properly placed in your user's home directory, you just need to login using the respective
private key:
For example:
Default location is ~/.ssh/id_rsa for private and ~/.ssh/id_rsa.pub for public key.
Ubuntu
Debian
Arch Linux
GnuPG is most widely used for having SSH (Secure Shell) connections without password or any means of interactive
authentication, which improves security level significantly.
Following sections describe ways to create, use, and maintain security of GnuPG keys.
Alternately, you can upload your public key to a public key server such as keys.gnupg.net so that others can use it.
To do so, enter the following in a terminal:
gpg —list-keys
Then, search for the 8-digit string (the primary ID) associated with the key you want to export. Then, issue the
command:
Now, the public key has been uploaded to the key server and is publicly available.
gpg --gen-key
gpg --list-keys
outputs:
Then publish:
The file format for the hosts file is specified by RFC 952
In case internal DNS server you can validate if this server resolve DNS names properly using dig command:
Add/Delete route
Option Description
add or del Add or delete a route
-host x.x.x.x Add route to a single host identified by the IP address
-net x.x.x.x Add route to a network identified by the network address
gw x.x.x.x Specify the network gateway
netmask x.x.x.x Specify the network netmask
default Add a default route
Examples:
Add/Delete route
Option Description
add or del or change or append
Change a route
or replace
show or flush the command displays the contents of the routing tables or remove it
restore restore routing table information from stdin
this command gets a single route to a destination and prints its contents exactly as
get
the kernel sees it
Examples:
Systemwide. You should modify the /etc/hosts file. You just have to add to that file a new line containing:
For a single user. You should modify the ~/.hosts file --- you-d have to create it. It is not as simple as for
systemwide. Here you can see an explanation.
For instance, you could add this line using the cat Unix tool. Suppose that you want to make a ping to a PC in yout
local network whose IP address is 192.168.1.44 and you want to refer to that IP address just by remote_pc. Then
you must write on your shell:
$ ping remote_pc
$ ifconfig -a
Example:
$ ifconfig eth0
eth0 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx
inet addr:x.x.x.x Bcast:x.x.x.x Mask:x.x.x.x
inet6 addr: xxxx::xxx:xxxx:xxxx:xxxx/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4426618 errors:0 dropped:1124 overruns:0 frame:0
TX packets:189171 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:382611580 (382.6 MB) TX bytes:36923665 (36.9 MB)
Interrupt:16 Memory:fb5e0000-fb600000
Example:
$ ethtool eth0
Examples
$ ip link show
$ ip addr show
DHCP If you are connected to a network with a DHCP server running, dhclient command can get an IP address for
your interface
$ dhclient <interface>
or alternatively, you could make a change to the /etc/network/interfaces file for the interface to be brought up
on boot and obtain DHCP IP
auto eth0
iface eth0 inet dhcp
If you want to statically configure the interface settings(permanent change), you could do so in the
/etc/network/interfaces file.
Example:
A static IP address could be added to an interface using the ifconfig utility as follows
Example:
F1 Displays help
F5 Copies the selected file to the directory open in the second panel
F6 Moves the selected file to the directory open in the second panel
F10 Exits mc
mcedit <filename>
F1 Displays help
F3 Marks the start of the text selection. Move cursor any direction to select. Second hit marks the end of the
selection.
cd /location/of/new/root
mount -t proc proc proc/
mount --rbind /sys sys/
mount --rbind /dev dev/
mount --rbind /run run/ (optionally)
3. If you need to use an internet connection in the chroot environment, copy over the DNS details:
cp /etc/resolv.conf etc/resolv.conf
4. Change root into /location/of/new/root, specifying the shell (/bin/bash in this example):
source /etc/profile
source ~/.bashrc
exit
cd /
umount --recursive /location/of/new/root
update
This option retrieves and scans the Packages.gz files, so that information about new and updated packages is
available. To do so, enter the following command:
upgrade
This option is used to install the newest versions of all packages currently installed on the system. Packages
currently installed with new versions available are retrieved and upgraded; under no circumstances are currently
installed packages removed, or packages not already installed retrieved and installed. To upgrade, enter the
following command:
dist-upgrade
In addition to performing the function of upgrade, dist-upgrade also intelligently handles changing dependencies
with new versions of packages. It will attempt to upgrade the most important packages at the expense of less
important ones if necessary. To do so, enter the following command:
To install a single package or list of packages (including dependencies), issue the following command:
source
search
This command will attempt to locate software packages in the configured software repositories that match the
given search criteria, and display the name / version / repository location of the matches it finds. To use it, enter the
following command:
install
This command will attempt to locate and install the named software from the configured software repositories,
recursively locating and installing any needed prerequisite software as well. To use it, enter the following command:
update
This option is used to install the newest versions of all packages currently installed on the system. Packages
currently installed with new versions available are retrieved and upgraded; new prerequisites are also retrieved and
installed as necessary, and replaced or obsoleted packages are removed. To upgrade, enter the following
command:
Unlike apt, most yum commands will also automatically check for updates to repository metadata if a check has
not been done recently (or if forced to do so) and will retrieve and scan updated metadata so that information
about new and updated packages is available before the requested operation is performed.
Use git if you want to stay in sync with the latest Ubuntu kernel source. Detailed instructions can be found in the
Kernel Git Guide. The git repository does not include necessary control files, so you must build them by:
Download the source archive - This is for users who want to rebuild the standard Ubuntu packages with additional
patches. Use a follow command to install the build dependencies and extract the source (to the current directory):
This is for users who want to modify, or play around with, the Ubuntu-patched kernel source.
tar xf linux-*.tar.xz
cd linux-*
make menuconfig
4. To accept the default configuration, press → to highlight < Exit > and then Return .
make
Note that you can use the -jem> flag to compile files in parallel and take advantage of multiple cores.
The compressed kernel image can be found at arch/[arch]/boot/bzImage, where [arch] is equal to uname -a.