Mostrar mensagens com a etiqueta Tutorials. Mostrar todas as mensagens
Mostrar mensagens com a etiqueta Tutorials. Mostrar todas as mensagens

sábado, 2 de abril de 2011

Log in Linux with an USB Pen Drive

Recently I had the idea in increase the security of my Netbook, so I think if it's possible to keep an user session only if an determinated USB pen drive is plugged. I have made an research and I found that there are already some tools to do that.
One of the most popular is pam_usb tools, this tool provides, among other things to do:
  • Password less authentication, use USB stick for that;
  • Two-factor authentication. USB stick and password to authenticate the user.
  • Support for all kind of removable devices (SD, MMC, etc);
  • It works with any application supporting PAM, such as su, any login manager (GDM, KDM), etc.
 How to install:
 First install needed packages:
apt-get install libpam-usb pamusb-tools
Connect the pen drive and add it to any name.
Note: Check if it's only one pen drive connected;
Note2: The data in pen drive is not erased.
pamusb-conf –add-device token

Now add the user account associated to that pen drive.
pamusb-conf –add-user youruser
Note: Answer all questions with 'yes'.

Check if all process is done correctly: 
pamusb-check youruser
If it says: Access Granted it's all ok.

Finally you must add " auth sufficient pam_usb.so" to file /etc/pam.d/common-auth.

From now you can login with your USB pen drive, but it's not all you can run an script and perform some action...For more information please visit the official page.



quarta-feira, 24 de fevereiro de 2010

Seting up a DHCP server

To quickly install and set up a DHCP server on Linux you need to download the DHCP software from here.
After the download do:
$ tar xzvf dhcp-4.1.1.tar.gz
After extract do:
$ cd dhcp-4.1.1/
$ ./configure
$ make; make install
 Now we have the dhcp server installed so we need to configure that.

The /etc/dhcpd.conf File

When the server starts it reads the dhcpd.conf file. In this file we need to pute the configurations that we wish to our network.

Normally this file is NOT created in installation, but you can:

$ touch /etc/dhcpd.conf

Finally we need to edit the file for our case.
So let's see an example that explains the most important fields. Adapt for your case:
ddns-update-style interim
ignore client-updates
 
subnet 192.168.1.0 netmask 255.255.255.0 {
 
   # The range of IP addresses the server
   # will issue to DHCP enabled PC clients
   # booting up on the network
 
   range 192.168.1.201 192.168.1.220;
 
   # Set the amount of time in seconds that
   # a client may keep the IP address

  default-lease-time 86400;
  max-lease-time 86400;
 
   # Set the default gateway to be used by
   # the PC clients
 
   option routers 192.168.1.1;
   # Don't forward DHCP requests from this
   # NIC interface to any other NIC
   # interfaces
 
   option ip-forwarding off;
 
   # Set the broadcast address and subnet mask
   # to be used by the DHCP clients
 
  option broadcast-address 192.168.1.255;
  option subnet-mask 255.255.255.0;
  
   # Set the NTP server to be used by the
   # DHCP clients

  option ntp-servers 192.168.1.100;

   # Set the DNS server to be used by the
   # DHCP clients

  option domain-name-servers 192.168.1.100;
 
   # If you specify a WINS server for your Windows clients,
   # you need to include the following option in the dhcpd.conf file:

  option netbios-name-servers 192.168.1.100;
 
   # You can also assign specific IP addresses based on the clients'
   # ethernet MAC address as follows (Host's name is "laser-printer":

  host laser-printer {
      hardware ethernet 08:00:2b:4c:59:23;
     fixed-address 192.168.1.222;
   }
}
#
# List an unused interface here
#
subnet 192.168.2.0 netmask 255.255.255.0 {
}
 To see more options:
$ man dhcp-options

So to start our DHCP server:
$ dhcpd start 



quinta-feira, 4 de fevereiro de 2010

segunda-feira, 1 de fevereiro de 2010

Add a script to run on boot

So if you have a script and you wish to run them each time you boot up. This will tell you how to do that.

Write a script. put it in the /etc/init.d/ directory.
Lets say you called it XPTO.
  • Give them execution privileges using:
$chmod + XPTO
  •  Now run

$update-rc.d XPTO defaults

You can check out
% man update-rc.d for more information. It is a Debian utility to install scripts. The option “defaults” puts a link to start XPTO in run levels 2, 3, 4 and 5. (and puts a link to stop XPTO into 0, 1 and 6.)

  • To know which runlevel you are in use:
  $runlevel


Add a Grub Splash Image

The grub selection menu does not have a image. If you want to add your images to that menu you can, doing this:


$sudo apt-get install grub-splashimages
This will put the images in:
/boot/grub/splashimages
To add your own do this:

$cd /boot/grub
$sudo ln -s splashimages/debsplash.xpm.gz splash.xpm.gz
$sudo update-grub

What we just did was to link /grub/boot/splash.xpm.gz to the debsplash.xpm.gz splash image, and then updated the grub menu.


sexta-feira, 29 de janeiro de 2010

Convert packages files with Alien

If you have an rpm file for a package you wish to install, and if you cannot find a .deb debian package , you can use the alien package converter application.

Alien is a program that converts various package formates. Like rpm, dpkg, stampede slp, and slackware tgz file formats. If you want to use a package from another distribution than the one you have installed on your system, you can use alien.
But attention Alien should not be used to replace important system packages. In general, if you can’t uninstall the package without breaking your system, don’t try to replace it with an alien version.

Installing Alien:
$sudo apt-get install alien 

Example, conversion of a RPM file into DEB:
$sudo alien -k name_of_rpm_file.rpm  
  • The option -k will keep the version number of RPM file.
  • You can see more option on the Alien manual.



To get an entire web site

In Linux is simple to get an entire web site without install any program:

$wget -r http://Site_that_you_want


Download Books from Google to see offline

First you need to put the Google Book URL in this site.(All download instructions are in that site).

After you have all jpg files corresponding to pages of the book in your Linux computer you need to convert this files to PDF. You can run this script on your directory that contains all JPG files:
#!/bin/bash
declare -a ARRAY
ARRAY=$(ls | grep .jpg | grep -v .pdf)

for i in $ARRAY; do
    mv "$i" "$i.pdf"
done
After you have all files in PDF extension you can use this command to join all PDF files:

$pdfjoin --outfile NAME.pdf *.pdf



You can install pdfjoin typing:
$sudo apt-get install pdfjoin

Enjoy ;-)

Shell Script that randomly change image on Linux Desktop

Use this script to randomly display a different image every x seconds. All the images on a given directory are chosen. An image will be chosen at random and displayed each time by the script.

Usage:
You pass to program the images directory that you wants and the interval time
$ ./change_wallpaper.sh "/home/USER_DIRECTORY/Pictures/" "60"

#código
#!/bin/bash
#Program made by
##António L. R. Mendes
function setPaper(){
    declare -a ARRAY
    PATH_IMG=$1
    TIME=$2
    ARRAY=$(ls $PATH_IMG | grep [jpg][png] | sort -R)
       
    for i in $ARRAY; do
        gconftool-2 -t str -s /desktop/gnome/background/picture_filename "$PATH_IMG/$i"
        sleep $TIME
    done
   
    setPaper $PATH_IMG $TIME

}



#we can config:
# $1 - path to the images
# $2 - time to change
PATH_IMG=$1
TIME=$2
if [ ! -d "$PATH_IMG" ]; then
    echo "The directory $PATH_IMG is not a valid directory."
    exit
fi

if [ ! $TIME -gt 0 ]; then
    echo "The time introduced is not valid so the default value is 60 sec."
    $TIME=60
fi


echo "Program will change images in $PATH_IMG every $TIME seconds."
setPaper $PATH_IMG $TIME