Linux
Linux
Operating System..................................................................................................................................3
Disk Operations.....................................................................................................................................4
File Operations......................................................................................................................................6
Users......................................................................................................................................................9
Network Operations............................................................................................................................10
Important Files....................................................................................................................................14
Shell Scripts.........................................................................................................................................15
SSH, IP-Sec & SSL.................................................................................................................................16
Operating System
Red Hat/ Fedora/ CentOS from same initial distribution
rpm –ivh <filename>.rpm (to install packages)
kill -9 3991
kill -9 oampAgent
mount|grep “/dev”
/dev/sda2 on / type ext3
/dev/sda1 on /media/Windows-XP-x64 type fuseblk
/dev/scd0 on /media/cdrom0 type iso9660 (or /mnt/cdrom)
/usr
/var For mail, printing, error log.
Server computers ought to have /var in a different partition.
/bin This is where most executable binaries go.
/tmp Some programs write temporary data files here.
/home This is where users home directories go.
/boot This is where your kernel images go.
/etc Configuration files
umount /mnt/upgrade
File system type. Other types you are likely to use are:
ext3 journaling sile system based on ext2
msdos DOS
hfs mac
iso9660 CDROM
nfs network file system
ls sep* (List all files start with sep) (Same like using grep)
cd ~ Home directory
cd .. Parent directory
SFTP
!ls -ltr (list the files in the local folder)
lcd /root (change the local folder)
vi <File Name>
vim <file Name>
x Delete a character
dd Delete a line
o Open a new line
p Paste
yy Copy line
Shift+g go to last line
:wq Save and exit
:q! Exit without Saving
Esc Command mode
Esc+i Edit mode
/<key> Search a key
n - Search next
N - Search previous
screen
screen -S <name> -L
(Screen commands are not stored under history. But it will be saves in
putty log)
groupadd <groupname>
useradd -G <group-name> <username>
usermod -aG <group-name> <username>
passwd <username>
passwd (will change current user password)
Define IPs
netconfig (start a menu to configure network) (Only in Red hat)
ifconfig eth0 up 192.168.0.5 mask 255.255.255.0 (IP)
ifconfig eth0 down
vi /etc/sysconfig/network-scripts/ifcfg-eth0 (Permanently)
DEVICE=eth0
BOOTPROTO=static
DHCPCLASS=
HWADDR=00:30:48:56:A6:2E
IPADDR=10.10.10.15
NETMASK=255.255.255.192
ONBOOT=yes
service network restart
Define Default GW
route add default gw 10.10.10.1 (Default Gateway)
vi /etc/sysconfig/network (Permanently)
NETWORKING=yes
HOSTNAME=myserver.example.com
GATEWAY=10.10.10.1
Define Routes
route add -net 172.22.31.160/27 gw 172.22.31.129 dev eth5.1514
tcpkill host 192.168.1.2 (To kill all TPC connections to/from the host)
FireWall (iptables)
iptables –L (list firewall configuration)
iptable –S (list firewall configuration)
service iptables stop (to Stop firewall)
Adding a rule (After that save and restart the network services may be requires)
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
-A - Add to the end of chain “INPUT”
-I - Add to the begining of chain “INPUT”
-R - Replace a rule
Removing a rule
iptables -D INPUT 5
Backup/Restore
iptables-save > iptables.dump
iptables-restore < iptables.dump
ifdown eth0
ifup eth0 or ifconfig eth0 up (to make interface up)
mii-tool
telnet 10.239.130.89 443 (To check the connectivity when only a specific port is open)
nslookup <FQDN>
TCP Dump
-C <file size> A new file will be created with a different number to the end (Mb)
-c Number of packets to display
-i <interface> Interface to monitor
-n Don't convert addresses to names
-s Set the max packet size. 0 mean 65535 (Default is also 65535) (Bytes)
-r Read a file
-w Write to a file
-W Number of files (Files will be overwritten)
-Z User
host <IP>
port <Port>
–vvv Display the details of the packet
-R Read Filter (packets that pass the read filter will be displayed or saved to the output file)
-f Capture Filter
-S Set a line seperator
cat /proc/memoryinfo
ntpdate ntpserver1
Important Files
Cat Display.sh
#! /bin/bash
# This a sample script
echo "Date and time is:"
date
echo
echo "Your username is: `whoami` \n"
echo "Your current directory is: \c"
pwd
echo
echo “Your Name is $1”
N1=10
N2=20
Let N3=$N1+$N2
echo “Value of N3 is $N3”
\n New line
\c Continue on the same line
Clear Clear the screen
echo $USERNAME (System Variables are in Block Caps)
n=10 (Define UDV with value 10)
msg1=one
msg2="$msg1 two" (if string has spaces include it in “”)
check_syscheck.sh file
#!/bin/bash
DATFile=/home1/mjayasun/check_syscheck.dat
TIME=$(date +"%T %d/%m/%Y")
$ - store the command value into variable
+ - Specify the format
# Email details
EMAIL_TO="MDS-Helpdesk@telefonica.com"
EMAIL_SUBJECT="PCRF/SPR syscheck Alert"
Server="${NODE%:*}" (remove shortest map from the end) (% remove from the end)
SrvType="${NODE##*:}" (remove longest map from the start) (# remove from the start)
if [ $? -eq 0 ]; then
echo "[INFO] Failure found for $Server ($SrvType)" | tee -a /home1/mjayasun/syscheck$(date
+%Y%m%d).log
If the last operation exit code ($?) is success. That means a FAILURE is found.
echo ""
echo "Completed !!!"
echo ""
exit 0
check_syscheck.dat file
SERVERS=csite-func1-tvoe:s csite-func1-pmac:s csite-func1-cmp1:s csite-func1-cmp2:s csite-func1-
sdmfront1:s csite-func1-sdmfront2:s csite-func1-sdmback1:s csite-func1-sdmback2:s
#
#
#
Columns are :- tag:ServerType,AlertTeam
#
s:Server,MDS
CronTab
crontab -e Edit current users crontab file, or create one if it doesn’t already exist.
crontab -l Display current users crontab file.
crontab -r Remove current users crontab file.
crontab –v
Eg:
0,15,30,45 * * * * /home1/mjayasun/check_syscheck.sh
Will run check_syscheck.sh in every 15 min
On the client machine, the user must generate a public / private keys.
If key is password protected, user will be prompted for the password every time he is going to
use the key.
fabio@morpheus:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/fabio/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/fabio/.ssh/id_rsa.
Your public key has been saved in /home/fabio/.ssh/id_rsa.pub.
The key fingerprint is:
44:3e:ef:58:94:15:52:c2:88:ca:ab:21:43:53:3d:42 fabio@morpheus
fabio@morpheus:~$
fabio@morpheus:~$ ssh-keygen -p
Enter file in which the key is (/home/fabio/.ssh/id_rsa):
Key has comment '/home/fabio/.ssh/id_rsa'
Enter new passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved with the new passphrase.
fabio@morpheus:~$
In this case, a new password was added. Note that this operation does not change the public /
private key pair. It only changes its encryption.
SSH comes with an utility called ssh-copy-id that simply adds the contents of client’s
~/.ssh/id_rsa.pub to the server’s ~/.ssh/authorized_keys:
fabio@morpheus:~$ ssh-copy-id -i .ssh/id_rsa.pub ornellas@apanela.com 15
ornellas@apanela.com's password:
Now try logging into the server, with "ssh 'ornellas@apanela.com'", and
check in:
.ssh/authorized_keys
Or
cat id_rsa.pub >> .ssh/authorized_keys
Access
At this point, user’s account on the server can be locked for password authentication. On
Linux systems, one can make:
On this case, the client’s key was encrypted and its password was asked. If it had no
password, nothing would have been asked, and access would be direct:
For Windows
Download putty.zip
Once you have accumulated enough entropy, the application generates the key.
Make sure you enter a lengthy passphrase in the Key passphrase field and confirm it in the
Confirm passphrase field.
Click on the Save private key button to save your private key in a file.
With your mouse, select the content of the box labeled Public key for pasting into OpenSSH
authorized_keys file, copy it (that is, hit Control-C).
Make it available for PuTTY-compliant applications
1. Under Session , enter the hostname of the Unix machine, and choose the SSH
protocol
2. Under Connection > Data , enter your login name for the Unix machine in Auto-login
username
3. Under Connection > SSH > Auth , select the filename of the private key that you
saved out of PuTTYGen
4. Back under Session , enter the hostname again in the box under Saved Sessions and
click Save
This is now added into the registry and all PuTTY applications are aware of it.
Load your key
Pageant is a utility that loads ssh keys in memory. If you load your ssh key with pageant, you
won't have to type your ssh key passphrase again and again.
First, run pageant.exe. Then load your ssh key by right-clicking on the pageant icon in the
system tray bar as shown below.
Click on the Add key menu item: a file dialog pops up.
Select the private key file you saved while running puttygen.exe and click on the Open
button: a new dialog pops up. Its title is Pageant: enter passphrase.
On Linux
#ls /home/<user>/.ssh
id_rsa.pub
known_hosts (public keys of other known servers)
authorized_keys
In ther server
#mv id_rsa.pub authorized_keys
Or
In the client.
#cat ~/.ssh/id_rsa.pub | ssh root@example.com 'cat - >>
~/.ssh/authorized_keys'