2011-02-01

Linux List The Open Ports And The Process That Owns Them

Ref: http://www.cyberciti.biz/tips/linux-display-open-ports-owner.html

How do you list the network open ports on your server and the process that owns them? The answer is simple use the following command (must run as root):
sudo lsof -i
sudo netstat -lptu

CentOS 5 FTP Setup (vsftpd)

Ref 1: http://www.linuxquestions.org/questions/fedora-35/vsftpd-error-553-could-not-create-file-390569
Ref 2: http://www.cyberciti.biz/tips/rhel-fedora-centos-vsftpd-installation.html

Disable SELinux on FTP, so that uploading works:
setsebool -P ftp_home_dir 1

Install the vsftpd package via yum command:
# yum install vsftpd

vsftpd Defaults


Default port: TCP / UDP - 21 and 20
The main configuration file: /etc/vsftpd/vsftpd.conf
Users that are not allowed to login via ftp: /etc/vsftpd/ftpusers

Configure Vsftpd Server


# vi /etc/vsftpd/vsftpd.conf

Turn off standard ftpd xferlog log format:
xferlog_std_format=NO
Turn on verbose vsftpd log format. The default vsftpd log file is /var/log/vsftpd.log:
log_ftp_protocol=YES
Above to directives will enable logging of all FTP transactions. Lock down users to their home directories:
chroot_local_user=YES
Create warning banners for all FTP users:
banner_file=/etc/vsftpd/issue
Turn on vsftpd on boot:
# chkconfig vsftpd on
Start the service:
# service vsftpd start
# netstat -tulpn | grep :21


Configure Iptables To Protect The FTP Server


# vi /etc/sysconfig/iptables
Add the following lines, ensuring that they appear before the final LOG and DROP lines for the RH-Firewall-1-INPUT:
-A RH-Firewall-1-INPUT -m state --state NEW -p tcp --dport 21 -j ACCEPT
Open file /etc/sysconfig/iptables-config, enter:
# vi /etc/sysconfig/iptables-config
Ensure that the space-separated list of modules contains the FTP connection tracking module:
IPTABLES_MODULES="OTHER_MODULES ip_conntrack_ftp"
Save and close the file. Restart firewall:
# service iptables restart

Tip: View FTP Log File
Type the following command:
# tail -f /var/log/vsftpd.log

Tip: Restrict Access to Anonymous User Only
Edit the vsftpd configuration file /etc/vsftpd/vsftpd.conf and add the following:
local_enable=NO

Tip: Disable FTP Uploads
Edit the vsftpd configuration file /etc/vsftpd/vsftpd.conf and add the following:
write_enable=NO

For upload to work except for anonymous, you might need to:
  • create a group, say ftpw
  • change the ownership of /var/ftp and its subdirectories to group ftpw
  • add ftpw group onto users with write privilege

2010-12-23

Notes on Compiling SeqHound

  1. Compile NCBI
    1. make sure link the actual makefile in platform/ to the root level
    2. make sure the paths in the linked makefile are modified to your environment
  2. Compile SLRI
    1. make sure $NCBI is set
    2. link lib/*.mk to root level
    3. cd lib && make lib
  3. Compile bzip2
  4. Compile libiodbc (as ODBC dependency)
  5. Set environment var $NCBI, $SLRI, $ODBC, and $BZDIR
  6. Comment out ValNodeUnique in seqhound/include/intrez_misc.h and seqhound/src/intrez_misc.c
  7. cd seqhound && ./makeallsh odbc all

2010-12-17

Secure GRUB

Version 1 (aka 0.98)
Reference cyberciti.biz
  1. #grub-md5-crypt
    Password:
    Retype password:
    $1$NYoR71$Sgv6pxQ6LG4GXpfihIJyL0
  2. # vi /boot/grub/menu.lst (Red Hat /boot/grub/grub.conf)
    Edit file and add a password line as follows:
    password --md5 $1$NYoR71$Sgv6pxQ6LG4GXpfihIJyL0

Sample config file:
default 0
timeout 5
password --md5 $1$NYoR71$Sgv6pxQ6LG4GXpfihIJyL0
title Debian GNU/Linux, kernel 2.6.13.4-cust-en-smp
root (hd0,0)
kernel /boot/vmlinuz root=/dev/hda3 ro
savedefault
boot


Version 2 (aka 1.98)
Reference ubuntuforums.org

Linux notes

skill -STOP -u username Pause somebody.
skill -KILL -u username Kick out somebody.
skill -KILL -v /dev/pts/* Kick all out.

last show successful logins
lastb show bad logins
lastlog show latest logins of all/any users.
/var/log/btmp bad logins
/var/log/wtmp successful logins
/var/run/utmp current logins

Set date and time
# date -s "2 OCT 2006 18:00:00"
# date --set="2 OCT 2006 18:00:00"
# date +%Y%m%d -s "20081128"
# date +%T -s "10:13:13"

Get hardware info
/sbin/lspci
/sbin/lsusb
lshw

route -n
shows the routing table, the gateway will be flagged with a 'G'

If DNS is not properly configured, go to /etc/resolv.conf, check or add line nameserver x.x.x.x

To pipe wget download content:
wget -q url -O - | cat > abc.txt

For ubuntu 10.10
Edit /etc/default/grub & run update-grub to set the booting preferences

2010-12-16

Ubuntu Server 10.10 (As desktop use)

Hate OpenOffice? Dislike the integrated IM software? Feel sick about GNOME games? This solution might help to build the desktop from scratch that avoids most unnecessary components.

Installation:
  1. Get a ubuntu server iso, and install it the debian way.
  2. Modify /etc/apt/sources.list to your satisfaction.
  3. Configure Medibuntu source: https://help.ubuntu.com/community/Medibuntu

Addition:
  • Basic:
    • vim
  • Desktop:
    • xserver-xorg
    • gnome-core
    • gdm
    • gnome-themes-selected
    • humanity-icon-theme
    • gcalctool (the calculator)
    • chromium-browser
    • gnome-screensaver
    • flashplugin-installer
    • language-support-??
    • *network-manager
    • *network-manager-openconnect (for Cisco AnyConnect VPN)
    • *wine
  • Security:
    • vlock
  • Development:
    • g++
    • openjdk-6-jre
    • qt4-dev-tools
    • *dia
    • *mysql-server
    • *mysql-admin
    • *python-mysqldb
  • Remote access:
    • vinagre (the client)
    • vino (the server)
  • Media:
    • vlc
    • mozilla-plugin-vlc
    • libdvdcss2
    • ubuntu-restricted-extras
  • Printing:
    • system-config-printer-gnome
    • cups
    • *smbclient (for Windows shared printing)
    • *hplip (HP printer drivers)

Configuration:
  • Clear screen when logout:
    1. ~/.bash_logout
    2. insert single command clear
  • Disable Ctrl-Alt-Del:
    1. /etc/init/control-alt-delete.conf
    2. comment out the actual command line
  • Secure login/out logs:
    1. sudo chmod 640 `sudo find /var -name ?tmp`
  • Stop GDM from auto starting:
    1. /etc/init/gdm.conf
    2. comment out all "start on" stuff
  • Configure GRUB:
    1. /etc/default/grub
    2. update-grub
  • MySQL
    1. /etc/mysql/my.cnf
    2. to reset root password: sudo dpkg-reconfigure mysql-server-5.1

2010-11-02

Building CLucene

Note: done on Ubuntu 10.10.
Note 2: if no need for snapshot features, there is a pre-built package in the repo, called libclucene-dev.

Download CLucene source (tgz).

Install necessary dependency for building:
  • g++
  • zlib1g-dev
  • cmake

Make a new folder, and cd into it. Run cmake <clucene-source-folder>.
Then ccmake <clucene-source-folder> to turn on static library build.

If you get an error complaining undeclared INT_MAX in file src/core/CLucene/search/spans/TermSpans.cpp, insert #include <limits.h> at the beginning of that file.

2010-08-11

Google Sites API

  1. get XHTML text
    ((XhtmlTextConstruct) entry.getTextContent().getContent()).getXhtml().getBlob()
  2. get plain text (no xml tags)
    entry.getTextContent().getContent().getPlainText().
  3. update xhtml
    XmlBlob newBlob = new XmlBlob();
    newBlob.setBlob(updatedXml);
    entry.setContent(new XhtmlTextConstruct(newBlob));
    entry.update();
    System.out.println("Updated " + getEntryId(entry.getId()));
  4. get all entries (possible failure in getting all entries if there is a write action to the server during these code)
    List<ContentFeed> feeds = new LinkedList<ContentFeed>();
    
    int startIndex = 1;
    while (true) {
    q.setStringCustomParameter("start-index",
    String.valueOf(startIndex));
    ContentFeed contentFeed = client.query(q, ContentFeed.class);
    int entrySize = contentFeed.getEntries().size();
    if (entrySize > 0) {
    feeds.add(contentFeed);
    startIndex += entrySize;
    System.out.println(getEntryId(contentFeed.getEntries().get(0).getId()));
    } else {
    break;
    }
    }
  5. Download a file using browser-accessible URL:
    private byte[] getData(String url) {
    
    MediaContent mc = new MediaContent();
    mc.setUri(url);
    MediaSource msrc;
    try {
    msrc = client.getMedia(mc);
    InputStream in = msrc.getInputStream();
    return org.apache.commons.io.IOUtils.toByteArray(in);
    } catch (Exception e) {
    return null;
    }
    }
  6. Alternative to download a file using browser-accessible URL:
    private byte[] getData(String url) {
    
    try {
    ILink link = new com.google.gdata.model.atom.Link("alternate", null, url);
    GDataRequest req = client.createLinkQueryRequest(link);
    req.execute();
    InputStream in = req.getResponseStream();
    return org.apache.commons.io.IOUtils.toByteArray(in));
    } catch (Exception e) {
    return null;
    }
    }
  7. Retrieve the entry corresponding to a browser-accessible URL(http://sites.google.com/site/siteName/path/to/the/page):
    ContentQuery query = new ContentQuery(new URL(buildContentFeedUrl()));
    
    query.setPath("/path/to/the/page");
    ContentFeed contentFeed = client.getFeed(query, ContentFeed.class);
    for (BaseContentEntry entry : contentFeed.getEntries()) {
    // do something with the entry
    }

2010-07-23

Fedora 13 on MacBook Pro 5,5

Materials
MacBook Pro 13" (2009)
Fedora 13 i386 DVD (I don't wanna tackle x86_64 problems)
Internet access

Initial install
Install rEFIt on Mac OS X.
Reboot, and install Fedora using the DVD.
Reboot, and synchronzie the partition table in startup rEFIt menu.
Reboot, (I mean REBOOT) and choose the newly installed system.

Repositoies
Install the repo rpm from:
RPM Fusion free
RPM Fusion nonfree
Adobe i386
Configure Google repository according to this page.
Don't forget to sudo yum update!

Get things to work
Graphics card
sudo yum install kmod-nvidia-PAE
Note: the nvidia proprietary driver will not give you the fancy startup and shutdown animations.
Wireless
sudo yum install kmod-wl-PAE
MIT VPN
Create a VPN connection in NetworkManager, using Cisco AnyConnect, and point the gateway to vpn.mit.edu. (Yes, it simply works)
Exchange support
Exchange 2007
sudo yum install evolution-mapi (it seems it doesn't work in my case)
Pre 2007
sudo yum install evolution-exchange
Other apps
  • Utility
    sudo yum install flash-plugin
    sudo yum install alacarte # menu editor
    sudo yum install dia
    sudo yum install picasa
    sudo yum install unrar
    sudo yum install pitivi # video converter
    sudo yum install google-chrome-stable

  • Network analysis
    sudo yum install nmap
    sudo yum install ettercap-gtk
    sudo yum install wireshark-gnome

  • Others
    sudo yum install xiphos # the Holy Bible

Blender
Additional dependencies could be avoided if the python version matches the downloadable version (and currently it does).
Download from http://www.blender.org/download/get-blender, unpack, and it's ready to go.
VirtualBox
Download VirtualBox yum repo file: http://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo.
Put it in /etc/yum.repo.d/. Then:
sudo yum install dkms
The default dependency resolver won't get the right PAE kernel source. Fix it:
sudo yum install kernel-PAE-source
sudo yum erase kernel-source
If you didn't install g++, do it:
sudo yum install gcc-c++
Finally:
sudo yum install VirtualBox-3.2
If output shows the kernel modules are not properly built, recheck the above vbox dependencies, and:
sudo /etc/init.d/vboxdrv setup
Rerun the above command if you had updated your kernel.
Drop vbox users into vboxusers group.
ATTENTION: before you hop in the vm, make sure the host key is accessible... there is NO "right control" in macbook's keyboard.

Results
Sound
Built-in speakers can't make any waves, but plug-in earphones do.
Fn keys
Brightness keys do display something on screen. But if you really want to adjust the brightness, do it in nvidia configuration panel.
No keyboard back-light.

2010-07-22

Google Data API Feed URLs

Google Sites

SiteFeed

https://sites.google.com/feeds/site/<domain-name>/

ContentFeed

https://sites.google.com/feeds/content/<domain-name>/<site-name>/<content-id>/

Reference



Google Analytics


ManagementFeed

  • Accounts: https://www.google.com/analytics/feeds/datasources/ga/accounts
  • Web properties: https://www.google.com/analytics/feeds/datasources/ga/accounts/~all/webproperties
  • Profiles: https://www.google.com/analytics/feeds/datasources/ga/accounts/~all/webproperties/~all/profiles

DataFeed

https://www.google.com/analytics/feeds/data

Reference