Showing posts with label Learn Linux. Show all posts
Showing posts with label Learn Linux. Show all posts

Thursday, April 24, 2014

Linux set default password expiry for all new users

Under Linux password related utilities and config file(s) comes from shadow password suite. The /etc/login.defs file defines the site-specific configuration for this suite. This file is a readable text file, each line of the file describing one configuration parameter. The lines consist of a configuration name and value, separated by whitespace.
You need to set default password expiry using /etc/login.defs file (password aging controls parameters):
  1. PASS_MAX_DAYS : Maximum number of days a password may be used. If the password is older than this, a password change will be forced.
  2. PASS_MIN_DAYS : Minimum number of days allowed between password changes. Any password changes attempted sooner than this will be rejected
  3. PASS_WARN_AGE : Number of days warning given before a password expires. A zero means warning is given only upon the day of expiration, a negative value means no warning is given. If not specified, no warning will be provided.
Open file /etc/login.defs using text editor:

# vi /etc/login.defs

Setup (sample) values as follows:

PASS_MAX_DAYS 30
PASS_MIN_DAYS 1
PASS_WARN_AGE 7

Close and save the file.

Friday, June 22, 2012

Scripts To Create Your Own Linux Distribution

Those familiar with Linux will be able to tweak settings, add and remove apps and customise the menu, toolbars and other desktop elements.
Incredibly, those are about all the skills you need to create your very own Linux distro. 
We're going to take a look at some scripts that'll help you customise different distros.

1. Remastersys
This tool has a newbie-proof GUI and works on both Ubuntu and Debian distros and any of their derivatives. 
Remastersys works by transferring the distro you're running into an ISO image. You can choose to include your settings and personal data too, which makes it ideal for backups.

2. UCK
The Ubuntu Customisation Kit – which is tastefully shortened to UCK – works with the ISO of any of the four Ubuntu flavours (the GNOME based original Ubuntu, KDE-based Kubuntu, Xfce-basedXubuntu and education-targeted Edubuntu) and lets you add or remove any apps to the stock. 
This tool is ideal for advanced users because during the customisation process it places you in a chrooted environment of the Live CD, enabling you to tweak any aspect of the distro.

3. Reconstructor
As the name suggests, this tool is a comprehensive suite for creating your own custom Ubuntu and Debian distros from an existing ISO image. It lets you tweak the wallpaper, themes, icons, applications, and more. 
The browser-based tool requires no installation, but you'll need to pay a small fee before you can use all of its features.

4. Revisor
Unlike the three tools above, this app is for the RPM-based distroFedora. Revisor has both a GUI and a command-line interface, and it can create USB Live media as well as install-only CDs and DVDs.
Instead of using ISO images, Revisor downloads packages from the internet, so it may take some time to compile depending on your connection speed and customised package selection.

5. SUSE Studio
Novell's SUSE Studio is taking the world by storm. It lets you select packages, set various configurations (including network detection, firewall settings and so on) and select a logo, background and more. 

The most impressive part is that all this functionality is accessed from within a browser. You can even test-drive your new distro – again from within the browser – before downloading the ISO image to share with the world.

6. Pungi
This is the tool that the Fedora developers use to spin the official releases. It's a command-line tool written in Python. 
Like Revisor, the tool gathers packages directly from the internet and then automatically splits them and creates CD-sized installable ISO images.

7. Builder
Builder is a series of bash scripts that are used by the gNewSense developers to create their distro. Along with the tool they've also written a handy nine-step guide to creating a customised distro from Ubuntu Hardy. The guide is available on their site.

8. Linux-Live 
If you want a truly distro-agnostic way of customising your favourite Linux distribution, you need the Linux-Live set of scripts. The scripts work on any installed Linux distro and can create a Live system that you can boot from optical media or USB drives. 
The popular Slackware -based Slax Live distro is built using these scripts, which work best on Slackware but can work on other distributions as well.

9. MySlax Creator
Here's a Slackware customisation script with a unique twist. The tool creates customised versions of the Slackware-based Slax distro we mentioned above, but unlike the other tools we talk about here, MySlax Creator installs and work from within Windows! 
It works with Slax ISO images and lets you add data to your own custom spins.

10. Linux From Scratch
If you're a Linux purist then you'll probably find the idea of using scripts and automated systems to create a distro quite abhorrent. Well, fear not. If you're keen to get your hands dirty, you'll need the definitive tome Linux From Scratch, a book that explains how to make your own Linux distro the very hardest way.

Tuesday, June 19, 2012

Basic Networking Command In Linux


IPconfing

Your connection to a network is made by your system through a particular hardware interface such as an Ethernet card of a modem. Data passing through this interface is then routed to your network. The ifconfig command configures your network interfaces and the route command sets up the network connections accordingly.
Ifconfig is used to configure the kernel-resident network interfaces.It is used at boot time to set up interfaces as necessary. If no arguments are given, ifconfig displays the status of the currently active interfaces. If a single interface argument is given, it displays the status of the given interface only.
Syntax : ifconfig < interface > < -host_net_flag > [address] [options]
where -host_net_flag can be either -host or -net to indicate a host or network IP address.
The -host flag is the default.
Usage Examples
#ifconfig eth0 192.168.0.1 => Configuring the Ethernet interface
#ifconfig eth0 192.168.0.1 broadcast 192.168.0.255 netmast 255.255.255.0  => Configuring eth0 including a broadcast address and the netmask
#ifconfig eth0 up  => To activate the interface eth0 after configuring it
#ifconfig -a  => If a single -a argument is given, it displays the status of all interfaces, even those that are down

Route

Determines where the process starts and to what computer your system needs to send the packet to reach the destination.
Usage Examples
#route  => To display the routing table
#route add 192.168.1.2 dev eth0  =>  To route an Ethernet interface
#route del 192.168.1.2  =>  To delete the route with IP address 192.168.1.2

For a gateway we first need to add a route and then add a route specifying it is a gateway.
#route add 192.168.1.2
#route add default gw 192.168.1.2  =>  gw here stands for gateway
#route add -net 192.168.23.0 gw dev eth1 => For a gateway to access a subnet

To add an IP address to another network interface we use the ifcofig and route commands with the new IP address.
#ifcofig eth1 192.168.1.3
#route add 192.168.1.3 dev eth1

arp

ARP stands for Address Resolution Protocol, which is used to find the media access control address of a network neighbour for a given IPv4 Address.
Usage Examples
#arp -e  => Display all ARP table entries for all interfaces
#arp -i eth0 -s 192.168.1.1 00:23:5a:c1:50:99  => Create a static ARP table entry associating IP address 192.168.1.1 with MAC address 00:23:5a:c1:50:99 available through the eth0 interface ( ‘i’ option stands for interface and ‘s’ option is used for setting up new table entry )
#arp -d 192.168.1.1  => Delete the ARP table entry for 192.168.1.1

traceroute

Traceroute is a utility that traces a packet from your computer to an Internet host showing how many hops the packet requires to reach the host and how long each hop takes.For a slow connection traceroute is used to check the route through which we are connected to a host , monitoring the speed and the number of intervening gateway connections a route takes.
Usage Example
#traceroute www.google.com
Sample Output for the above command:
traceroute to www.google.com (74.125.236.48), 30 hops max, 60 byte packets
1 172.19.16.1 (172.19.16.1) 1694.355 ms 1694.510 ms 1694.847 ms
2 iws1.iiita.ac.in (172.31.1.1) 0.869 ms 0.864 ms 0.902 ms
3 * * *
4 * * *
5 115.114.57.161.static-Mumbai.vsnl.net.in (115.114.57.161) 66.756 ms 66.750 ms 66.730 ms
6 115.113.163.70.static-pune.vsnl.net.in (115.113.163.70) 69.556 ms 69.287 ms 69.279 ms
7 209.85.241.52 (209.85.241.52) 62.766 ms 62.797 ms 64.210 ms
8 209.85.251.95 (209.85.251.95) 64.153 ms 64.162 ms 65.593 ms
9 209.85.241.33 (209.85.241.33) 65.855 ms 65.849 ms 64.820 ms
10 maa03s04-in-f16.1e100.net (74.125.236.48) 62.011 ms 62.001 ms 61.982 ms

netstat

Provides real time information on the status of the network connections, as well as the network statistics and routing table.
Usage Examples
#netstat -r       =>  Displays the routing table
#netstat -i       =>   Displays the uses of the different network interfaces.
#netstat -s      =>   Displays protocol( TCP , UDP , IP etc ) counts and errors

telnet

To remotely log in to another system on your network. Telnet operates as if we were logging in to another system from a remote terminal and asks for the login name and password.
#telnet hostname < port >
or
#telnet
telnet > open hostname < port >
Here the hostname can be either the domain name or the IP address.

nslookup

Nslookup is a command used to query the Internet domain name servers. Is useful in finding the domain name if the IP is known and vice-versa.
The host command can be used to carry out the same stuff too.
Usage Examples
#nslookup < domain name >        => To find the dotted decimal IP address of host name
#nslookup < IP address >            => To find the hostname of the dotted decimal IP address

ping

Detects whether a system is up and running.
Syntax : ping hostname
where hostname can be either domain name or IP address.
Usage Examples
#ping 172.19.16.47
From 172.19.16.47 icmp_seq=1 Destination Host Unreachable
From 172.19.16.47 icmp_seq=2 Destination Host Unreachable
From 172.19.16.47 icmp_seq=3 Destination Host Unreachable
From 172.19.16.47 icmp_seq=4 Destination Host Unreachable
From 172.19.16.47 icmp_seq=5 Destination Host Unreachable
From 172.19.16.47 icmp_seq=6 Destination Host Unreachable
#ping 172.19.16.6
PING 172.19.16.6 (172.19.16.6) 56(84) bytes of data.
64 bytes from 172.19.16.6: icmp_req=1 ttl=128 time=4.00 ms
64 bytes from 172.19.16.6: icmp_req=2 ttl=128 time=4.56 ms
64 bytes from 172.19.16.6: icmp_req=3 ttl=128 time=0.931 ms
64 bytes from 172.19.16.6: icmp_req=4 ttl=128 time=4.10 ms
64 bytes from 172.19.16.6: icmp_req=5 ttl=128 time=1.08 ms
64 bytes from 172.19.16.6: icmp_req=6 ttl=128 time=6.78 ms
Here in the first case the destination host is unreachable whereas in the second case the destination 172.19.6.16 sends the packets back ensuring good connectivity.

ssh

ssh (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine. It is intended to replace rlogin and rsh, and provide secure encrypted communications between two untrusted hosts over an insecure network.
Syntax : ssh username@hostname [command]
where username is your SSH username, and hostname is the host name or IP address of your Web server.
If its the first time we are trying to connect to this host machine we will get a warning saying authentication failure. Typing yes would automatically solve the problem.
Usage Examples
#ssh raju@192.168.1.1 -p 1020  => ssh as user raju into 192.168.1.1 port 1020
#ssh raju@192.168.1.1 cd /home/etc  => change the directory to /home/etc in the remote server 192.168.1.1

Basic Linux Command-line Tips and Tricks

1.  Everything in Linux is a file including the hardware and even the directories.
2. # : Denotes the super(root) user
3.  : Denotes the normal user
4.  /root: Denotes the super user’s directory
/home: Denotes the normal user’s directory.
5.  Switching between Terminals
§  Ctrl + Alt + F1-F6: Console login
§  Ctrl + Alt + F7: GUI login
6.  The Magic Tab: Instead of typing the whole filename if the unique pattern for a particular file is given then the remaining characters need not be typed and can be obtained automatically using the Tab button.
7.   ~(Tilde): Denotes the current user’s home directory
8.   Ctrl + Z: To stop a command that is working interactively without terminating it.
9.  Ctrl + C: To stop a command that is not responding. (Cancellation).
10.  Ctrl + D: To send the EOF( End of File) signal to a command normally when you see ‘>’.
11.  Ctrl + W: To erase the text you have entered a word at a time.
12.  Up arrow key: To redisplay the last executed command. The Down arrow key can be used to print the next command used after using the Up arrow key previously.
13.  The history command can be cleared using a simple option –c (clear).
14.  cd :   The cd command can be used trickily in the following ways:
cd : To switch to the home user
cd * : To change directory to the first file in the directory (only if the first file is a directory)
cd .. : To move back a folder
cd - : To return to the last directory you were in
15.  Files starting with a dot (.) are a hidden file.
16.   To view hidden files: ls -a
17.   ls: The ls command can be use trickily in the following ways:
ls -lR : To view a long list of all the files (which includes directories) and their subdirectories recursively .
ls *.* : To view a list of all the files with extensions only.
18.   ls -ll: Gives a long list in the following format
drwxr-xr-x 2 root root 4096 2010-04-29 05:17 bin where
drwxr-xr-x : permission where d stands for directory, rwx stands for owner privilege, r-x stands for the group privilege and r-x stands for others permission respectively.
Here r stands for read, w for write and x for executable.
2=> link count
root=>owner
root=>group
4096=> directory size
2010-04-29=>date of creation
05:17=> time of creation
bin=>directory file(in blue)

The color code of the files is as follows:
Blue: Directory file
White: Normal file
Green: Executable file
Yellow: Device file
Magenta: Picture file
Cyan: link file
Red: Compressed file
File Symbol
-(Hyphen) : Normal file
d=directory
l=link file
b=Block device file
c=character device file
19.  Using the rm command: When used without any option the rm command deletes the file or directory ( option -rf) without any warning. A simple mistake like rm / somedir instead of rm /somedir can cause major chaos and delete the entire content of the /(root) directory. Hence it is always advisable to use rm command with the -i(which prompts before removal) option. Also there is no undelete option in Linux.
20.  Copying hidden files: cp .* (copies hidden files only to a new destination)
21. dpkg -l : To get a list of all the installed packages.
23. Use of ‘ > ‘ and ‘ >> ‘ : The ‘ > ‘ symbol ( input redirector sign) can be used to add content to a file when used with the cat command. Whereas ‘ >> ‘ can be used to append to a file. If the ‘ >> ‘ symbol is not used and content is added to a file using only the ‘>’ symbol the previous content of the file is deleted and replaced with the new content.
e.g: $ touch text (creates an empty file)
$ cat >text
This is text’s text. ( Save the changes to the file using Ctrl +D)
$cat >> text
This is a new text. (Ctrl + D)
Output of the file:
This is text’s text.
This is a new text.

23.  To count the number of users logged in : who |wc –l

24.  cat:  The cat command can be used to trickly in the following way:
- To count no. of lines from a file : cat |wc -l
- To count no. of words from a file : cat |wc -w
To count no. of characters from a file : cat |wc –c

25.  To search a term that returns a pattern: cat |grep [pattern]

26.  The ‘tr’ command: Used to translate the characters of a file.
tr ‘a-z’ ‘A-Z’ <text >text1 : The command for example is used to translate all the characters from lower case to upper case of the ‘text’ file and save the changes to a new file ‘text1′.
27.  File permission using chmod: ‘chmod’ can be used directly to change the file permission of files in a simple way by giving the permission for root, user and others in a numeric form where the numeric value are as follows:
r(read-only)=>4
w(write)=>2
x(executable)=>1
e.g. chmod 754 text will change the ownership of owner to read, write and executable, that of group to read and executable and that of others to read only of the text file.
28.  more: It is a filter for paging through text one screenful at a time.
Use it with any of the commands after the pipe symbol to increase readability.
e.g. ls -ll |more
29.  cron : Daemon to execute scheduled commands. Cron enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates.
1 * * * * echo “hi” >/dev/tty1 displays the text “hi” after every 1 minute in tty1
.—————- minute (0 – 59)
| .————- hour (0 – 23)
| | .———- day of month (1 – 31)
| | | .——- month (1 – 12) OR jan,feb,mar,apr …
| | | | .—– day of week (0 – 7) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
* * * * * command to be executed
Source of example: Wikipedia
30.  fsck: Used for file system checking. On a non-journaling file system the fsck command can take a very long time to complete. Using it with the option -c displays a progress bar which doesn’t increase the speed but lets you know how long you still have to wait for the process to complete.
e.g. fsck -C
31.  To find the path of the commandwhich command
e.g. which clear
32. Setting up alias: Enables a replacement of a word with another string. It is mainly used for abbreviating a system command, or for adding default arguments to a regularly used command
e.g. alias cls=’clear’ => For buffer alias of clear
33.  The du (disk usage) command can be used with the option -h to print the space occupied in human readable form. More specifically it can be used with the summation option (-s).
e.g. du -sh /home summarizes the total disk usage by the home directory in human readable form.
34.  Two or more commands can be combined with the && operator. However the succeeding command is executed if and only if the previous one is true.
e.g. ls && date lists the contents of the directory first and then gives the system date.
35.  Surfing the net in text only mode from the terminal: elinks [URL]
e.g: elinks www.google.com
Note that the elinks package has to be installed in the system.
36.  The ps command displays a great more deal of information than the kill command does.
37.  To extract a no. of lines from a file:
e.g head -n 4 abc.c is used to extract the first 4 lines of the file abc.c
e.g tail -n 4 abc.c is used to extract the last 4 lines of the file abc.c
38.  Any changes to a file might cause loss of important data unknowingly. Hence    Linux creates a file with the same name followed by ~ (Tilde) sign without the recent changes. This comes in really handy when playing with the configuration files as some sort of a backup is created.
39.   A variable can be defined with an ‘=’ operator. Now a long block of text can be assigned to the variable and brought into use repeatedly by just typing the variable name preceded by a $ sign instead of writing the whole chunk of text again and again.
e.g ldir=/home/my/Desktop/abc
cp abcd $ldir copies the file abcd to /home/my/Desktop/abc.
40. To find all the files in your home directory modified or created today:
e.g. find ~ -type f -mtime 0