Showing posts with label UNIX. Show all posts
Showing posts with label UNIX. Show all posts

Friday, January 14, 2011

Convert OpenSSH RSA or DSA key to PEM format

RSA to PEM

First create an RSA key using OpenSSH tools:

$ ssh-keygen -t rsa

Then converted it to PEM format:

$ openssl rsa -in ~/.ssh/id_rsa -outform pem > id_rsa.pem

DSA to PEM

First create an DSA key using OpenSSH tools:

$ ssh-keygen -t dsa

Then converted it to PEM format:

$ openssl dsa -in ~/.ssh/id_dsa -outform pem > id_dsa.pem

Saturday, October 3, 2009

kill process based on username and logout users

To kill all process of logged in user and logout

pkill -KILL -u username

Know Number of Logged in User in FreeRadius from Shell

This is a very useful perl script that i created to know how many user are logged in on FreeRadius from the UNIX/Linux shell or command line.

It’s for FreeRadius with MySQL and I think it is usefull for other radiuses as well.
Below is the full code.

#!/usr/bin/perl -w

use DBI;

my $db = 'radius';
my $db_host = 'localhost';
my $db_username = 'username';
my $db_password = 'password';
my $dbh = DBI->connect("dbi:mysql:database=$db;host=$db_host:port number;user=$db_username;password=$db_password") or die "Couldn't connect to database: $DBI::errstr\n";

my $sql = qq{SELECT DISTINCT UserName,AcctStartTime,FramedIPAddress,CallingStationId FROM radacct WHERE AcctStopTime = '0000-00-00 00:00:00' AND NASIPAddress = '192.168.254.2' GROUP BY UserName};

$sth = $dbh->prepare($sql) or die "Couldn't prepare query '$sql': $DBI::errstr\n";

$sth->execute() or die "Couldn't execute query '$sql': $DBI::errstr\n";

print $sth->rows();

$sth->finish();

$dbh->disconnect();

exit;

Note:
change the username and password to actual username and password of a MySQL database, and NASIPAddress.

Monday, April 20, 2009

FreeBSD VLANs Configuration using ifconfig command

To create a new VLAN interface, enter:
# ifconfig {vlan-name} create

To associate the VLAN interface with a physical interface and assign a VLAN ID, IP address, and netmask:
# ifconfig {vlan-name} {ip-address} netmask {subnet-mask} vlan {vlan-id} vlandev {physical-interface}

The following examples, all packets will be marked on egress with 802.1Q VLAN tags, specifying a VLAN ID of 500:
# ifconfig vlan500 10.0.0.1 netmask 255.255.255.0 vlan500 vlandev em0

To remove a VLAN interface, enter:
# ifconfig {vlan-name} destroy

To make configuration persistence, open /etc/rc.conf:
# vi /etc/rc.conf

Append / modify as follows:
cloned_interfaces=“vlan500 vlan600”
ifconfig_vlan500="inet x.x.x.x netmask y.y.y.y vlan 500 vlandev em0"
ifconfig_vlan600="inet x.x.x.x netmask y.y.y.y vlan 600 vlandev em0"

Saturday, January 3, 2009

Static ARP entry

arp -s ip_address ethernert_address

example:

arp -s 192.168.69.126 00:1f:f3:52:20:ed

arp -S ip_address ethernert_address
- Is just like -s except any existing ARP entry for this host will be deleted first.

example:

arp -S 192.168.69.126 00:1f:f3:52:20:ed