Showing posts with label CLI. Show all posts
Showing posts with label CLI. Show all posts

Wednesday, December 26, 2012

how to check open port on ubuntu

simply  run this CLI

netstat -anltp | grep "LISTEN"

Monday, May 7, 2012

Thursday, November 10, 2011

vi search

Vi: Search and Replace

Change to normal mode with .

Search (Wraped around at end of file):

  Search STRING forward :   / STRING.
Search STRING backward: ? STRING.

Repeat search: n
Repeat search in opposite direction: N (SHIFT-n)

Replace: Same as with sed, Replace OLD with NEW:
First occurrence on current line:      :s/OLD/NEW

Globally (all) on current line: :s/OLD/NEW/g

Between two lines #,#: :#,#s/OLD/NEW/g

Every occurrence in file: :%s/OLD/NEW/g

Thursday, May 5, 2011

How to block port 80 on ubuntu

I just block my port 80 by using this CLI

iptables -A INPUT -j DROP -p tcp --destination-port 80 -i eth0

The code above will drop all tcp packets coming into your Linux computer on device eth0 on port 80. If your Internet connection runs through a device other than eth0, go ahead and make the adjustment.

To remove the iptables rule use the following code:

iptables -D INPUT -j DROP -p tcp --destination-port 80 -i eth0

credit to : foogazi


Monday, June 28, 2010

Install SNMPD on Ubuntu

1.Installation

root@ibsen:~# sudo apt-get install snmpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libmpich1.0gf libdc1394-22 genisoimage linux-headers-2.6.27-7 libgfortran2 dvd+rw-tools linux-headers-2.6.27-7-generic libcarp-clan-perl libxml-xql-perl libparse-yapp-perl
rdate python-xml localechooser-data gcc-4.2-base libimage-size-perl libdebconfclient0 libvisual-0.4-0 libmyth-python perlmagick libvisual-0.4-plugins libavdevice52
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
libperl5.10 libsensors3 libsnmp-base libsnmp15
Suggested packages:
lm-sensors
The following NEW packages will be installed:
libperl5.10 libsensors3 libsnmp-base libsnmp15 snmpd
0 upgraded, 5 newly installed, 0 to remove and 3 not upgraded.
Need to get 2463kB of archives.
After this operation, 7987kB of additional disk space will be used.
Do you want to continue [Y/n]?

answer y

2. Configuration

Move existing /etc/snmp/snmpd.conf configuration file to /etc/snmp/snmpd.conf.org

mv /etc/snmp/snmpd.conf  /etc/snmp/snmpd.conf.org

Create a new /etc/snmp/snmpd.conf file:

rocommunity  public
syslocation "PDC, Peters DataCenter"
syscontact peter@it-slav.net

Make snmpd use the newly created file and make it listen to all interfaces:

Edit /etc/default/snmpd

Change from:

# snmpd options (use syslog, close stdin/out/err).
SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid 127.0.0.1'

To:

# snmpd options (use syslog, close stdin/out/err).
#SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid 127.0.0.1'
SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid -c /etc/snmp/snmpd.conf'

and restart snmpd

/etc/init.d/snmpd restart


Credit to http://www.it-slav.net/blogs/2009/02/05/install-and-configure-snmp-on-ubuntu/

Tuesday, June 15, 2010

make symbolic link on Unix

# ln -s /usr/home /home or ln -s /data/moodle2/ moodle2

Thursday, June 3, 2010

list all installed application on ubuntu

list all installed application on ubuntu

dpkg --get-selections

Tuesday, June 1, 2010

Centos - Adduser

You can also do this from the command line, below are the equivalent commands. You need to have root level access to use the commands below.
  • usr/sbin/useradd [options] login_name
    creates a new user
  • usr/sbin/usermod [options] login_name
    modifies a user’s attributes
  • usr/sbin/userdel [options] login_name
    deletes the specified user. Use the -r option to automatically remove the user’s home directory and mail spool.
  • usr/bin/passwd login_name
    sets the password for the specified user
  • usr/sbin/groupadd [options] group_name
    creates a new group
  • usr/sbin/groupmod [options] group_name
    modifies a group’s attributes
  • usr/sbin/groupdel group_name
    deletes the specified group

Wednesday, May 19, 2010

Repair table MYSQL

Today i face 1 problem when i want mysqldump my D. my error is

Incorrect key file for table 'mdl_block_instance'; try to repair it

This command to help you to auto-repair your table on mysql

mysqlcheck -uusername -p --auto-repair namedatabase

Monday, March 22, 2010

Mysqldump

this how the usual CLI for mysqldump
mysqldump -u username -p dbname > backupname.sql

restore back from mysql

mysql -u username -p dbname '<' yousqldumpfile.sql

Recently, I was facing problem to restore a UTF8-Enabled database which stores a lot of Arabic text in the db itself.

I have to re-dump back the db by appending the --default-character-set=charset_name option in the dump command :

mysqldump -uroot -p --default-character-set=utf8 --databases yourdbname > yourdumpfile.sql

To restore, again you have to append the same option :

mysql -uroot -p --default-character-set=utf8 '<' youdumpsql.sql ** i need to add '<' because i will become hidden in this blog,if you want tu use the sqldump please to remove ' at '<' on restore CLI.

Thanks

Tuesday, March 2, 2010

htpasswd tips

to add another user on htpasswd file

htpasswd -s alimdevpass username

Sunday, February 21, 2010

Update / Upgrade Ubuntu Server

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade


If the kernel or kernel modules have been updated, you should reboot your computer/server.

Thursday, February 11, 2010

No netwrok after clone/copy using VMWare ESX

After making a copy/clone of an ubuntu server 8.10, i face a network problem.

1. "ifconfig" shows no eth0 device, just the 127.0.0.1 loopback
2. "/etc/init.d/networking restart" reports:

SIOCSIFADDR: No such device
eth0: ERROR while getting interface flags: No such device
SIOCSIFNETMASK: No such device
SIOCSIFBRDADDR: No such device
eth0: ERROR while getting interface flags: No such device
Failed to bring up eth0.

Solution
When you create a complete clone/copy of your vmware machine, a new ethernet MAC address is assigned.

follow this step :
as a root
run this CLI
# rm -fr /etc/udev/rules.d/70-*
# reboot

after wakeup, try ifconfig.
now you get your network back.

Salud!

Tuesday, February 9, 2010

SUDO on FreeBSD

as root install

sudo located at /usr/ports/security/sudo
make configure
make && make install

edit conf at

ee /usr/local/etc/sudoers

example and edit :

# Runas alias specification

# User privilege specification
root ALL=(ALL) ALL
kenan ALL=(www) ALL

note :

This Sudo command limits the user's power on the basis of the configuration made on the file "/etc/sudoers".
Generally in default case you might see something like this:

root ALL=(ALL) ALL
Above, you can see ALL 3 times. But what does it mean?
The first ALL: Run from any(all) host
The Second ALL: From any Terminal
The third ALL: Can Run any command

example :
usename ALL=(group) ALL


** note : !/usr/bin/su (this will prevent user to sudo su)

General sudoers File Record Format
usernames/group servername = (usernames command can be run as) command

Lock / Unlock user on FreeBSD

Lock user :

pw lock nameuser

unlock user :

pw unlock nameuser

Wednesday, January 13, 2010

Add HDD on VMWARE (FreeBSD)

I just finish adding HDD onto my Vmware server.

the step :

- choose vm that you wish to add the HDD
- edit setting
- add and choose HDD
- follow the instruction
- after adding go to server (freebsd)
- type sysinstall
- choose fdisk
- BEWARE! please make sure your HDD before you format it!
- after you choose your HDD, choose A and W (write the HDD)
- after finish,exit and choose label
- choose C (create) , edit the label and W (write) the HDD.
- edit the fstab (ee /etc/fstab)

example :
but beware too remember the path your HDD before edit the fstab.

/dev/da1s1d /data ufs rw 2 2

- save and reboot.

Setting in FSTAB add HDD in FreeBSD or Unix

ee /etc/fstab

/dev/da2s1 /studentdata ufs rw 2 2

Sunday, January 10, 2010

SUDO in FreeBSD / Unix

as root install

sudo located at /usr/ports/security/sudo
make configure
make && make install

edit conf at

ee /usr/local/etc/sudoers

example and edit :

# Runas alias specification

# User privilege specification
root ALL=(ALL) ALL
kenan ALL=(www) ALL

example :
usename ALL=(group) ALL


** note : !/usr/bin/su (this will prevent user to sudo su)

Set environment : setenv EDITOR ee


General sudoers File Record Format
usernames/group servername = (usernames command can be run as) command

Wednesday, January 6, 2010

Check RAM on FreeBSD

Install :

# cd /usr/ports/sysutils/freecolor
# make install clean

$ freecolor -m -o

Sunday, December 20, 2009

Set time zone on Ubuntu

Here the CLI :
as root or sudo

dpkg-reconfigure tzdata