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
T Shark
-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 “”)
crontab -e Edit your crontab file, or create one if it doesn’t already exist.
crontab -l Display your crontab file.
crontab -r Remove your crontab file.
crontab –v
Eg:
0,15,30,45 * * * * /mjayasun/check_syscheck.sh
Will run check_syscheck.sh in every 15 min
SSH
TL: Identification
String Exchange
Connection: Data is
encrypted using Shared
Key (K) and verified using
Hash (H).
Symmetrical encryption: Encrypt the entire connection ("shared secret" encryption or "secret key"
encryption). Prior to Authentication.
Asymmetrical encryption: During the initial key exchange process used to set up the symmetrical
encryption (used to encrypt the session), asymmetrical encryption is used. In this stage, both parties
produce temporary key pairs and exchange the public key in order to produce the shared secret that
will be used for symmetrical encryption. The public and private key pairs used for this part of the
procedure are completely separate from the SSH keys used to authenticate a client to the server.
Also, it is used in SSH key-based authentication. SSH key pairs can be used to authenticate a client
to a server. The client creates a key pair and then uploads the public key to any remote server it
wishes to access. This is placed in a file called authorized_keys within the ~/.ssh directory in the user
account's home directory on the remote server.
After the symmetrical encryption is established to secure communications between the server and
client, the client must authenticate to be allowed access. The server can use the public key in this file
to encrypt a challenge message to the client. If the client can prove that it was able to decrypt this
message, it has demonstrated that it owns the associated private key. The server then can set up the
environment for the client.
Hashing: Another form of data manipulation that SSH takes advantage of is cryptographic hashing.
Cryptographic hash functions are methods of creating a succinct "signature" or summary of a set of
information. Their main distinguishing attributes are that they are never meant to be reversed, they
are virtually impossible to influence predictably, and they are practically unique.
Given these properties, hashes are mainly used for data integrity purposes and to verify the
authenticity of communication. The main use in SSH is with HMAC, or hash-based message
authentication codes. These are used to ensure that the received message text is intact and
unmodified. SSH use MAC (Message Authentication Code) for hashing.
Algorithm Negotiation
Both parties agree on a large prime number, which will serve as a seed value.
Both parties agree on an encryption generator (typically AES), which will be used to
manipulate the values in a predefined way.
Independently, each party comes up with another prime number which is kept secret from the
other party. This number is used as the private key for this interaction (different than the
private SSH key used for authentication).
The generated private key, the encryption generator, and the shared prime number are used
to generate a public key that is derived from the private key, but which can be shared with the
other party.
Both participants then exchange their generated public keys.
The receiving entity uses their own private key, the other party's public key, and the original
shared prime number to compute a shared secret key. Although this is independently
computed by each party, using opposite private and public keys, it will result in
the same shared secret key.
The shared secret is then used to encrypt all communication that follows.
SSH - Public key authentication
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:
Now try logging into the server, with "ssh '[email protected]'", 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:
Make sure the SSH-2 RSA parameter is selected at the bottom of the window and click on the
Generate button.
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 [email protected] 'cat - >>
~/.ssh/authorized_keys'
First provide the RSA sw device serial number to the access administrator.
Passcode=PIN + tokencode
If your token requires a PIN, you normally create your PIN during your first RSA SecurID
authentication
Use the following procedure if the SecurID desktop application displays the Tokencode screen and your VPN
client application requests a passcode (or a PIN and tokencode).
Note: Your user name is normally the user name that you use to log on to your desktop.
To complete first-time authentication:
1.Start the SecurID desktop application on your desktop.
The Tokencode screen is displayed.
2.Connect to your VPN client.
3.In the User Name field, enter the user name that your administrator assigned.
You are prompted for a passcode.
4.In the SecurID desktop application, click the Copy button to copy the tokencode.
5.Return to the VPN client and paste the tokencode in the Passcode field.
You are prompted to create a PIN.
6.Follow the prompts to create and confirm your PIN.
Use the PIN format that your administrator specified. Memorize your PIN. After you create your PIN,
you are prompted for a new passcode.
7.Enter your PIN in the Passcode field.
8.Return to the SecurID desktop application and wait for the tokencode to change. After the tokencode
changes, click the Copy button to copy the tokencode.
9.Return to the VPN client. Paste the tokencode next to your PIN. Click OK to submit your passcode.
IP sec (Internet Protocol Security)
https://networklessons.com/cisco/ccie-routing-switching/ipsec-internet-protocol-security
Creating a tunnel
IKE (Internet Key Exchange)
IKE phase 1 – For setting up the IKE phase 2 tunnel
Use Internet Security Association and Key Management Protocol (ISAKMP)
IKE phase 2 – IPSec Tunnel
SSL - Secure Socket layer (“https” and use port 443 by default)
Also Connected to 172.30.167.6 (172.30.167.6) port 30600 (#0) will verify the IP path is ok on that
port
Digital Signatures