顯示具有 Linux Service 標籤的文章。 顯示所有文章
顯示具有 Linux Service 標籤的文章。 顯示所有文章

2011年5月2日 星期一

Linux Service - SNMP

Compile netsnmp
./configure --prefix=install-path
make

SNMPGET
snmpget
./snmpget -v 2c -c public IP-Address SNMPv2-MIB::sysUpTime.0


SNMPWALK
# ./snmpwalk -v 2c -c public IP-Address 1.3.6.1.2.1.1.1
SNMPv2-MIB::sysDescr.0 = STRING: system-Descriptions
[root@localhost apps]# ./snmpwalk -v 2c -c public IP-Address 1.3.6.1.2.1.1
SNMPv2-MIB::sysDescr.0 = STRING: DOCSIS 3.0 Cable Modem <SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprisesOBJECTID
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (1094660) 3:02:26.60
SNMPv2-MIB::sysContact.0 = STRING:
SNMPv2-MIB::sysName.0 = STRING:
SNMPv2-MIB::sysLocation.0 = STRING:
SNMPv2-MIB::sysServices.0 = INTEGER: 2
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (0) 0:00:00.00
SNMPv2-MIB::sysORID.1 = OID: SNMPv2-SMI::zeroDotZero
SNMPv2-MIB::sysORDescr.1 = STRING:
SNMPv2-MIB::sysORUpTime.1 = Timeticks: (0) 0:00:00.00

2010年9月13日 星期一

Linux Service - setup nessus

1. download the nessus rpm. My host was FC8, so I download the Fedora Core 6 package: Nessus-4.2.2-fc6.i386.rpm.
# rpm -ivh Nessus-4.2.2-fc6.i386.rpm

2. After extract the files from tar ball, then create a nessus root user.
# /opt/nessus/sbin/nessus-adduser

3. Register on the nessus web site, and nessus will send a registration feedback mail in clude the serial code. Include the following messages
>>>
+ Linux and Solaris Users :
To activate your account, simply execute the following command :
# /opt/nessus/bin/nessus-fetch --register WEBEVAL-E607-9C72-E426-8695-5424
>>>

So I simplify run the directed command
# /opt/nessus/bin/nessus-fetch --register WEBEVAL-E607-9C72-E426-8695-5424

4. Start the nessus daemon
# /opt/nessus/sbin/nessus-service -D
Copyright 2004-2010, Tenable Network Security, Inc. 25
nessusd (Nessus) 4.2.2 for Linux
(C) 1998 - 2008 Tenable Network Security, Inc.
Processing the Nessus plugins...
[##################################################]
All plugins loaded

5. Use browser to connect to the nessus host, like following link. My nessus host was located in the private network.
https://172.25.104.16:8834/ ==> Note, here is "https" service

6. Construct a nessus "Policy" to define the testing behavior

7. Construct a nessus "Scan" to utilize the pre-setting Policy


nessusd will play the role of scan server. And we can use any browser to connect the nessusd resident server. And then control nessusd (set policy/issue scan/view report...). Another way we can use nessus as a client daemon to control nessusd.


check feed types
# cat /opt/nessus/lib/nessus/plugins/plugin_feed_info.inc
PLUGIN_SET = "201009122334";
PLUGIN_FEED = "HomeFeed (Non-commercial use only)";

update the most recent plugins
# /opt/nessus/sbin/nessus-update-plugins

check what the feed type you are current usage
# /opt/nessus/bin/nessus-fetch --check

we can check the plugin load/unload messages through the following files. (We must enable the feature by click the Edit Policy->General->Scan->Log Scan Details to Server option)
# ls -la /opt/nessus/var/nessus/logs/nessusd.messages

messages was something like this >>
[Tue Sep 14 12:04:12 2010][7322.3407] user xxx : launching torture_cgi_inject_html.nasl against 192.168.0.1 [4979]
[Tue Sep 14 12:04:12 2010][7322.3407] torture_cgi_header_injection.nasl (process 4978) finished its job in 0.018 seconds
[Tue Sep 14 12:04:12 2010][7322.3407] user xxx : launching torture_cgi_redirection.nasl against 192.168.0.1 [4980]
[Tue Sep 14 12:04:12 2010][7322.3407] torture_cgi_inject_html.nasl (process 4979) finished its job in 0.018 seconds

2010年6月6日 星期日

Linux Service - Firewall, NAT - iptables

Enable the FTP Passive mode to login ftp server which installed iptables firewall rules

[root@localhost net]# /sbin/modprobe nf_conntrack_ftp
[root@localhost net]# /sbin/modprobe nf_nat_ftp

[root@localhost net]# /sbin/lsmod | grep ftp
nf_nat_ftp 6721 0
nf_conntrack_ftp 10725 1 nf_nat_ftp
nf_nat 18393 3 nf_nat_ftp,ipt_MASQUERADE,iptable_nat
nf_conntrack 50453 7 nf_nat_ftp,nf_conntrack_ftp,xt_state,ipt_MASQUERADE,iptable_nat,nf_nat,nf_conntrack_ipv4


# cat /etc/sysconfig/iptables
*nat
:PREROUTING ACCEPT [2071492:180971620]
:POSTROUTING ACCEPT [2118:149186]
:OUTPUT ACCEPT [1956:140466]
-A POSTROUTING -s 172.16.0.0/255.255.0.0 -o eth8 -j MASQUERADE
-A POSTROUTING -s 17.17.0.0/255.255.0.0 -o eth8 -j MASQUERADE
COMMIT

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
-A RH-Firewall-1-INPUT -m multiport -p tcp --destination-ports 111,635,52845 -j ACCEPT
-A RH-Firewall-1-INPUT -m multiport -p udp --destination-ports 111,635,52845 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -m tcp -p tcp --sport 20 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW,ESTABLISHED -m tcp -p tcp --dport 21 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -m tcp -p tcp --sport 1024: --dport 1024: -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 904 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
#-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT



# /sbin/iptables -L -v -n
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
1936 141K RH-Firewall-1-INPUT all -- * * 0.0.0.0/0 0.0.0.0/0

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination

Chain OUTPUT (policy ACCEPT 1473 packets, 143K bytes)
pkts bytes target prot opt in out source destination

Chain RH-Firewall-1-INPUT (1 references)
pkts bytes target prot opt in out source destination
0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 icmp type 255
0 0 ACCEPT esp -- * * 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT ah -- * * 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT udp -- * * 0.0.0.0/0 224.0.0.251 udp dpt:5353
0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:631
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:631
12 830 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 multiport dports 111,635,52845
0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 multiport dports 111,635,52845
1328 98880 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED tcp spt:20 ==> The rule seems not the root rule of the FTP passive mode problem
4 206 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW,ESTABLISHED tcp dpt:21
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED tcp spts:1024:65535 dpts:1024:65535 ==> The rule seems not the root rule of the FTP passive mode problem
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:904
592 40943 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited

The difference between FTP active and passive mode

Active FTP vs. Passive FTP, a Definitive Explanation

http://slacksite.com/other/ftp.html

Contents:

* Introduction
* The Basics
* Active FTP
* Active FTP Example
* Passive FTP
* Passive FTP Example
* Other Notes
* Summary
* References
* Appendix 1: Configuration of Common FTP Servers


Introduction

One of the most commonly seen questions when dealing with firewalls and other Internet connectivity issues is the difference between active and passive FTP and how best to support either or both of them. Hopefully the following text will help to clear up some of the confusion over how to support FTP in a firewalled environment.

This may not be the definitive explanation, as the title claims, however, I've heard enough good feedback and seen this document linked in enough places to know that quite a few people have found it to be useful. I am always looking for ways to improve things though, and if you find something that is not quite clear or needs more explanation, please let me know! Recent additions to this document include the examples of both active and passive command line FTP sessions. These session examples should help make things a bit clearer. They also provide a nice picture into what goes on behind the scenes during an FTP session. Now, on to the information...

The Basics

FTP is a TCP based service exclusively. There is no UDP component to FTP. FTP is an unusual service in that it utilizes two ports, a 'data' port and a 'command' port (also known as the control port). Traditionally these are port 21 for the command port and port 20 for the data port. The confusion begins however, when we find that depending on the mode, the data port is not always on port 20.

Active FTP

In active mode FTP the client connects from a random unprivileged port (N > 1023) to the FTP server's command port, port 21. Then, the client starts listening to port N+1 and sends the FTP command PORT N+1 to the FTP server. The server will then connect back to the client's specified data port from its local data port, which is port 20.

From the server-side firewall's standpoint, to support active mode FTP the following communication channels need to be opened:

* FTP server's port 21 from anywhere (Client initiates connection)
* FTP server's port 21 to ports > 1023 (Server responds to client's control port)
* FTP server's port 20 to ports > 1023 (Server initiates data connection to client's data port)
* FTP server's port 20 from ports > 1023 (Client sends ACKs to server's data port)

When drawn out, the connection appears as follows:
In step 1, the client's command port contacts the server's command port and sends the command PORT 1027. The server then sends an ACK back to the client's command port in step 2. In step 3 the server initiates a connection on its local data port to the data port the client specified earlier. Finally, the client sends an ACK back as shown in step 4.

The main problem with active mode FTP actually falls on the client side. The FTP client doesn't make the actual connection to the data port of the server--it simply tells the server what port it is listening on and the server connects back to the specified port on the client. From the client side firewall this appears to be an outside system initiating a connection to an internal client--something that is usually blocked.

Active FTP Example

Below is an actual example of an active FTP session. The only things that have been changed are the server names, IP addresses, and user names. In this example an FTP session is initiated from testbox1.slacksite.com (192.168.150.80), a linux box running the standard FTP command line client, to testbox2.slacksite.com (192.168.150.90), a linux box running ProFTPd 1.2.2RC2. The debugging (-d) flag is used with the FTP client to show what is going on behind the scenes. Everything in red is the debugging output which shows the actual FTP commands being sent to the server and the responses generated from those commands. Normal server output is shown in black, and user input is in bold.

There are a few interesting things to consider about this dialog. Notice that when the PORT command is issued, it specifies a port on the client (192.168.150.80) system, rather than the server. We will see the opposite behavior when we use passive FTP. While we are on the subject, a quick note about the format of the PORT command. As you can see in the example below it is formatted as a series of six numbers separated by commas. The first four octets are the IP address while the last two octets comprise the port that will be used for the data connection. To find the actual port multiply the fifth octet by 256 and then add the sixth octet to the total. Thus in the example below the port number is ( (14*256) + 178), or 3762. A quick check with netstat should confirm this information.

testbox1: {/home/p-t/slacker/public_html} % ftp -d testbox2
Connected to testbox2.slacksite.com.
220 testbox2.slacksite.com FTP server ready.
Name (testbox2:slacker): slacker
---> USER slacker
331 Password required for slacker.
Password: TmpPass
---> PASS XXXX
230 User slacker logged in.
---> SYST
215 UNIX Type: L8
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
ftp: setsockopt (ignored): Permission denied
---> PORT 192,168,150,80,14,178
200 PORT command successful.
---> LIST
150 Opening ASCII mode data connection for file list.
drwx------ 3 slacker users 104 Jul 27 01:45 public_html
226 Transfer complete.
ftp> quit
---> QUIT
221 Goodbye.


Passive FTP

In order to resolve the issue of the server initiating the connection to the client a different method for FTP connections was developed. This was known as passive mode, or PASV, after the command used by the client to tell the server it is in passive mode.

In passive mode FTP the client initiates both connections to the server, solving the problem of firewalls filtering the incoming data port connection to the client from the server. When opening an FTP connection, the client opens two random unprivileged ports locally (N > 1023 and N+1). The first port contacts the server on port 21, but instead of then issuing a PORT command and allowing the server to connect back to its data port, the client will issue the PASV command. The result of this is that the server then opens a random unprivileged port (P > 1023) and sends the PORT P command back to the client. The client then initiates the connection from port N+1 to port P on the server to transfer data.

From the server-side firewall's standpoint, to support passive mode FTP the following communication channels need to be opened:

* FTP server's port 21 from anywhere (Client initiates connection)
* FTP server's port 21 to ports > 1023 (Server responds to client's control port)
* FTP server's ports > 1023 from anywhere (Client initiates data connection to random port specified by server)
* FTP server's ports > 1023 to remote ports > 1023 (Server sends ACKs (and data) to client's data port)

When drawn, a passive mode FTP connection looks like this:
In step 1, the client contacts the server on the command port and issues the PASV command. The server then replies in step 2 with PORT 2024, telling the client which port it is listening to for the data connection. In step 3 the client then initiates the data connection from its data port to the specified server data port. Finally, the server sends back an ACK in step 4 to the client's data port.

While passive mode FTP solves many of the problems from the client side, it opens up a whole range of problems on the server side. The biggest issue is the need to allow any remote connection to high numbered ports on the server. Fortunately, many FTP daemons, including the popular WU-FTPD allow the administrator to specify a range of ports which the FTP server will use. See Appendix 1 for more information.

The second issue involves supporting and troubleshooting clients which do (or do not) support passive mode. As an example, the command line FTP utility provided with Solaris does not support passive mode, necessitating a third-party FTP client, such as ncftp.

With the massive popularity of the World Wide Web, many people prefer to use their web browser as an FTP client. Most browsers only support passive mode when accessing ftp:// URLs. This can either be good or bad depending on what the servers and firewalls are configured to support.

Passive FTP Example

Below is an actual example of a passive FTP session. The only things that have been changed are the server names, IP addresses, and user names. In this example an FTP session is initiated from testbox1.slacksite.com (192.168.150.80), a linux box running the standard FTP command line client, to testbox2.slacksite.com (192.168.150.90), a linux box running ProFTPd 1.2.2RC2. The debugging (-d) flag is used with the FTP client to show what is going on behind the scenes. Everything in red is the debugging output which shows the actual FTP commands being sent to the server and the responses generated from those commands. Normal server output is shown in black, and user input is in bold.

Notice the difference in the PORT command in this example as opposed to the active FTP example. Here, we see a port being opened on the server (192.168.150.90) system, rather than the client. See the discussion about the format of the PORT command above, in the Active FTP Example section.

testbox1: {/home/p-t/slacker/public_html} % ftp -d testbox2
Connected to testbox2.slacksite.com.
220 testbox2.slacksite.com FTP server ready.
Name (testbox2:slacker): slacker
---> USER slacker
331 Password required for slacker.
Password: TmpPass
---> PASS XXXX
230 User slacker logged in.
---> SYST
215 UNIX Type: L8
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> passive
Passive mode on.
ftp> ls
ftp: setsockopt (ignored): Permission denied
---> PASV
227 Entering Passive Mode (192,168,150,90,195,149).
---> LIST
150 Opening ASCII mode data connection for file list
drwx------ 3 slacker users 104 Jul 27 01:45 public_html
226 Transfer complete.
ftp> quit
---> QUIT
221 Goodbye.


Other Notes

A reader, Maarten Sjouw, pointed out that active FTP will not function when used in conjunction with a client-side NAT (Network Address Translation) device which is not smart enough to alter the IP address info in FTP packets.

Summary

The following chart should help admins remember how each FTP mode works:

Active FTP :
command : client >1023 -> server 21
data : client >1023 <- server 20

Passive FTP :
command : client >1023 -> server 21
data : client >1023 -> server >1023

A quick summary of the pros and cons of active vs. passive FTP is also in order:

Active FTP is beneficial to the FTP server admin, but detrimental to the client side admin. The FTP server attempts to make connections to random high ports on the client, which would almost certainly be blocked by a firewall on the client side. Passive FTP is beneficial to the client, but detrimental to the FTP server admin. The client will make both connections to the server, but one of them will be to a random high port, which would almost certainly be blocked by a firewall on the server side.

Luckily, there is somewhat of a compromise. Since admins running FTP servers will need to make their servers accessible to the greatest number of clients, they will almost certainly need to support passive FTP. The exposure of high level ports on the server can be minimized by specifying a limited port range for the FTP server to use. Thus, everything except for this range of ports can be firewalled on the server side. While this doesn't eliminate all risk to the server, it decreases it tremendously. See Appendix 1 for more information.

2010年5月24日 星期一

Linux Server - Delta UPS power manager software

Ever use the Delta UPS, the type is 水瓶座Plus系列

http://www.delta.com.tw/ch/product/ps/ups/index.asp

Download software
http://59.125.232.140/tc/index.aspx

電力管理大師2000 v3.01.26
The software package mainly contains 2 daemons, upsd and monitor

start upsd
# /usr/local/smart/upsd
or
# /usr/local/smart/upsd start

stop upsd
# /usr/local/smart/upsd stop

Another daemon "monitor" was a GUI X program that can configure/monitor the UPS status.

But it seems not stable in the Fedora/CentOS 64bits platform.

2010年4月11日 星期日

PPTP (VPN) connect using pptp client

While I first time try to use pptp client to build the VPN connection. There were various problems occuring in the setup procedures. The most one is that I am not clear understand there are many firewall/NAT routers that set up with pptp blocking rules (don't allow pptp traffics passing through), so we must use private NAT router to allow pptp connections passing through.

We can use Linux pptp client to build the pptp connection under linux system.
http://pptpclient.sourceforge.net/howto-fedora-core-6.phtml

Install PPTP and the pptpconfig GUI using the following commands:

Step1.
# rpm -Uvh http://pptpclient.sourceforge.net/yum/stable/fc6/pptp-release-current.noarch.rpm
# yum --enablerepo=pptp-stable install pptpconfig

Step2.
enter the server, domain, username and password into the Server tab.

Step3.
In my case, I don't need the following setting.
if your PPTP connection need encryption like MPPE, (your administrator says encryption is required), then on the Encryption tab, click on Require Microsoft Point-to-Point Encryption (MPPE).

Step4.
click on Add, and the tunnel will appear in the list.

Step5.
Click on the tunnel to select it, click on Start, and a window will appear with the tunnel connection log and status.

Step6.
if the connection succeeded, you can try the Ping test button. If the ping fails, you should try to find out why before proceeding. If the ping works, then the tunnel is active and you may now work on routing.

Step7.
In most case, the system will produce a new "ppp0" network interface. This is the point to point network interface that the local LAN traffic will communicate with remote pptp server.

We can add the routing entries like following example to specify dedicated routing domains via the ppp interface (If we clear know which destination routing domains)
# route add -net ${NET} dev ${IFACE}
e.g.
# route add -net 192.168.18.0/24 dev ppp0

or simply change the default route to the ppp0 ip address
# route del default
# route add default gw ${PPP0-IFACE-IP-Address}

2009年12月3日 星期四

Linux Service - Monitoring tools

Cacti
* http://www.cacti.net/
* written in PHP

MRTG
* http://oss.oetiker.ch/mrtg/
* written in Perl

2009年4月9日 星期四

Linux Service - NFS

Server side:
Edit the config file
/etc/exports
/usr/local/src/folder *(ro,insecure)

We can use exportfs to display the current exported file folder
# exportfs -rv

Client side
# mount -t nfs IP-Address:exported-folder mount-folder
e.g.
# mount -t nfs 172.17.11.100:/usr/local/src/folder /mnt/nfs

2008年10月27日 星期一

Apache, MySQL service

# mysqld and apached is the same usage in the linux
/usr/local/mysql/bin/mysqld_safe &
/usr/local/apache2/bin/apachectl start

Q. How to disable httpd port 443 listening?
In the /etc/httpd/conf.d folder, there are many modules configure file. One config file named ssl.conf is the https setting.
Mark the line of "Listen 443", and then the httpd launch will not bind on the port 443 anymore.

PS. /etc/httpd/conf/httpd.conf is the main apache config file.
/etc/httpd/conf.d/ contains all the apache sub-module config files.


/sbin/ipnat -f /etc/ipnat.conf
/sbin/sysctl -w net.inet.ip.forwarding=1
/usr/share/denyhosts/daemon-control start

2008年5月20日 星期二

Linux Service - cvs pserver & ssh

Two method to access the CVS server - ssh vs pserver
* Setup cvs server via ssh (port 22) -- client use ext method to connect
* Setup cvs server via cvs connection (port 2401) -- client use pserver to connect

How to Setup a CVS pserver
http://comsci.liu.edu/~murali/cvs/pserver.htm
Assumptions:

*

RedHat 6.1 Installed
*

Repository will reside in /usr/local/cvsroot. You can change this.

Needed:

*

CVS v1.10.6-2 is installed (RPM is on RedHat CD if not already installed)

Repository Installation:

1.

Login as root on repository machine
2.

Create a user (& group) called: cvs
3.

Create repository:

cvs -d /usr/local/cvsroot init

(Repeat this process if you want to create multiple repositories e.g., /usr/local/cvsroot2, /usr/local/cvspublic etc). Each repository can have different sets of authorized users.
4.

Change owner and group of repository and all files to cvs:

chown -R cvs.cvs /usr/local/cvsroot

5.

Create tcp service by editing /etc/services - add line (NOTE: May already be present):

cvspserver 2401/tcp #CVS PServer

6.

Create inetd entry for service by editing /etc/inetd.conf - add following lines:

#
# CVS PServer
#
cvspserver stream tcp nowait cvs /usr/bin/cvs cvs --allow-root=/usr/local/cvsroot pserver

NOTE: The above line "cvspserver stream ..." must appear on a single line. If you created multiple repositories in step 3, add an additional --allow-root=[repository path] argument for each repository.
7.

Restart inetd. NOTE: Because you will be restarting inetd from root's session, it will inherit the environment, most notably HOME=/root. This causes the following error when you try to check anything out of the repository:

cvs server: cannot open /root/.cvsignore: Permission denied
cvs [server aborted]: can't chdir(/root): Permission denied

To remedy this, use one of two methods.
1) The first method is to restart the server (the problem does not occur when inetd is started during system startup.
2) The second method is a manual restart while logged in as root. For this to work you need to restart inetd without the HOME pointing to root's home directory. Start a terminal session and enter the following:

unset HOME
/etc/rc.d/init.d/inet restart

8.

Now login as the user cvs. We will now setup the password file for cvs users.
9.

You will need a utility to create encrypted passwords. You can use the below perl script for that purpose:

#!/usr/bin/perl

srand (time());
my $randletter = "(int (rand (26)) + (int (rand (1) + .5) % 2 ? 65 : 97))";
my $salt = sprintf ("%c%c", eval $randletter, eval $randletter);
my $plaintext = shift;
my $crypttext = crypt ($plaintext, $salt);

print "${crypttext}\n";

10.

Create a text file in /usr/local/cvsroot/CVSROOT called passwd and enter the users as shown below (format is: userid:encrypted-password:cvs ):

username1:x$5itFdsw123:cvs
username2:3fgRH4p3443:cvs

NOTE: Use the crypt.pl utilty from above to generate the encrypted passwords for the above entries. The passwords for the users should NOT be the same as their unix password (if they have a unix account). The cvs users you enter above do NOT need a unix account.
11.

Set restrictive permissions on the file:

chmod 400 /usr/local/cvsroot/CVSROOT/passwd

12.

(optional) Repeat step 10 and 11 for each additional repository you created in step 3.

Repository Testing

1.

Set the default repository in the environment (will save entering it on every cvs command):

export CVSROOT=:pserver:username1@your_server_name:/usr/local/cvsroot

(substitute real values for username1, your_server_name and repository path if needed)
2.

Test the basic login:

cvs login

Enter the username1's password. There should not be any error messages.
3.

Create a tiny test project:

cd
mkdir testproj
echo "//Main Class">testproj/Main.java

4.

Import the project to the repository.

cd testproj
cvs import -m "My initial project message" testproj mycompany start

5.

Check to make sure the project was created in the repository. You should see the file Main.java in /usr/local/cvsroot/testproj
6.

Remove the test project from the repository:

rm --R /usr/local/cvsroot/testproj

2008年5月19日 星期一

SSH Without a Password, it is work for me :)

Copy from the following link
http://www.csua.berkeley.edu/~ranga/notes/ssh_nopass.html

The following steps can be used to ssh from one system to another without specifying a password.
Notes:

* The system from which the ssh session is started via the ssh command is the client.
* The system that the ssh session connects to is the server.
* These steps seem to work on systems running OpenSSH.
* The steps assume that a DSA key is being used. To use a RSA key substitute 'rsa' for 'dsa'.
* The steps assume that you are using a Bourne-like shell (sh, ksh or bash)
* Some of this information came from:
http://www.der-keiler.de/Mailing-Lists/securityfocus/Secure_Shell/2002-12/0083.html

Steps:

1. On the client run the following commands:

$ mkdir -p $HOME/.ssh
$ chmod 0700 $HOME/.ssh
$ ssh-keygen -t dsa -f $HOME/.ssh/id_dsa -P ''

This should result in two files, $HOME/.ssh/id_dsa (private key) and $HOME/.ssh/id_dsa.pub (public key).

Note:
The possible key type include the following choices (refer to the man page of ssh-keygen)
-t type
Specifies the type of key to create. The possible values are “rsa1” for protocol version
1 and “rsa” or “dsa” for protocol version 2.

DESCRIPTION of the ssh-keygen
ssh-keygen generates, manages and converts authentication keys for ssh(1). ssh-keygen can create
RSA keys for use by SSH protocol version 1 and RSA or DSA keys for use by SSH protocol version 2.
The type of key to be generated is specified with the -t option. If invoked without any arguments, ssh-keygen will generate an RSA key for use in SSH protocol 2 connections.

2. Copy $HOME/.ssh/id_dsa.pub to the server.
3. On the server run the following commands:

$ cat id_dsa.pub >> $HOME/.ssh/authorized_keys2 (Or you can just copy the file id_dsa.pub as the name "authorized_keys", # cp $HOME/.ssh/id_dsa.pub $HOME/.ssh/authorized_keys)

$ chmod 0600 $HOME/.ssh/authorized_keys2

Depending on the version of OpenSSH the following commands may also be required:

$ cat id_dsa.pub >> $HOME/.ssh/authorized_keys
$ chmod 0600 $HOME/.ssh/authorized_keys

An alternative is to create a link from authorized_keys2 to authorized_keys:

$ cd $HOME/.ssh && ln -s authorized_keys2 authorized_keys

4. On the client test the results by ssh'ing to the server:
$ ssh -i $HOME/.ssh/id_dsa server

5. (Optional) Add the following $HOME/.ssh/config on the client:

Host server
IdentityFile ~/.ssh/id_dsa

This allows ssh access to the server without having to specify the path to the id_dsa file as an argument to ssh each time.

Helpful manpages:

* ssh(1)
* ssh-keygen(1)
* ssh_config(5)

2008年3月9日 星期日

Linux Service - DHCP

I am not understand dhcp very well. The following is my experience about dhcp.

DHCP packet flow
Client -- send DHCP Discover
Server -- send DHCP Offer
Client -- send DHCP Request
Server -- send DHCP ACK

These four packets all contain the same Transaction ID
DHCP protocols use option to carry the main messages. These options include message type, server identifier, IP address lease time, renewal time value and rebinding time value etc..


dhcp running daemon
/sbin/dhclient -1 -q -lf /var/lib/dhcp/dhclient-eth0.leases -pf /var/run/dhclient-eth0.pid eth0

dhcp configuration file
/var/lib/dhcp/dhclient-eth0.leases
lease {
interface "eth0";
fixed-address 192.168.1.4;
option subnet-mask 255.255.255.0;
option routers 192.168.1.254;
option dhcp-lease-time 604800; ==> one week
option dhcp-message-type 5;
option domain-name-servers 168.95.1.1,140.113.1.1;
option dhcp-server-identifier 192.168.1.254;
option dhcp-renewal-time 302400;
option dhcp-rebinding-time 453600;
option domain-name "";
renew 0 2008/2/10 19:31:07;
rebind 3 2008/2/13 04:01:58;
expire 4 2008/2/14 22:01:58;
}
lease {
interface "eth0";
fixed-address 192.168.1.4;
option subnet-mask 255.255.255.0;
option routers 192.168.1.254;
option dhcp-lease-time 604800; ==> one week
option dhcp-message-type 5;
option domain-name-servers 168.95.1.1,140.113.1.1;
option dhcp-server-identifier 192.168.1.254;
option dhcp-renewal-time 302400;
option dhcp-rebinding-time 453600;
option domain-name "";
renew 3 2008/2/13 21:31:39;
rebind 6 2008/2/16 01:31:07;
expire 0 2008/2/17 19:31:07;
}
lease {
interface "eth0";
fixed-address 192.168.1.4;
option subnet-mask 255.255.255.0;
option routers 192.168.1.254;
option dhcp-lease-time 604800;
option dhcp-message-type 5;
option domain-name-servers 168.95.1.1,140.113.1.1;
option dhcp-server-identifier 192.168.1.254;
option dhcp-renewal-time 302400;
option dhcp-rebinding-time 453600;
option domain-name "";
renew 6 2008/2/16 17:36:07;
rebind 2 2008/2/19 03:31:39;
expire 3 2008/2/20 21:31:39;
}
lease {
interface "eth0";
fixed-address 192.168.1.4;
option subnet-mask 255.255.255.0;
option routers 192.168.1.254;
option dhcp-lease-time 604800;
option dhcp-message-type 5;
option domain-name-servers 168.95.1.1,140.113.1.1;
option dhcp-server-identifier 192.168.1.254;
option dhcp-renewal-time 302400;
option dhcp-rebinding-time 453600;
option domain-name "";
renew 1 2008/3/10 17:58:49;
rebind 3 2008/3/12 12:55:15;
expire 5 2008/3/14 06:55:15;
}
lease {
interface "eth0";
fixed-address 192.168.1.101;
option subnet-mask 255.255.255.0;
option routers 192.168.1.254;
option dhcp-lease-time 86400;
option dhcp-message-type 5;
option domain-name-servers 192.168.1.254;
option dhcp-server-identifier 192.168.1.254;
renew 2 2008/3/11 03:37:46;
rebind 2 2008/3/11 14:58:50;
expire 2 2008/3/11 17:58:50;
}
lease {
interface "eth0";
fixed-address 192.168.1.2;
option subnet-mask 255.255.255.0;
option routers 192.168.1.254;
option dhcp-lease-time 86400;
option dhcp-message-type 5;
option domain-name-servers 192.168.1.254;
option dhcp-server-identifier 192.168.1.254;
renew 2 2008/3/11 15:28:19;
rebind 3 2008/3/12 00:37:47;
expire 3 2008/3/12 03:37:47;
}

# if you want dhcpd to listen only on the specific interface, add the interface parameter in the dhcpd config file, as following steps
a. update /etc/sysconfig/dhcpd, add " eth1" as the listening interface
DHCPDARGS=" eth1"

b. restart the dhcpd
# service dhcpd restart

c. verify that dhcpd is launched with the " eth1" as the parameter
# ps auxwww | grep dhcpd
root 3848 0.0 0.1 6208 1212 ? Ss 14:51 0:00 /usr/sbin/dhcpd eth1



### Setup the dhcp config
And we config the /etc/dhcpd.conf to include the following options to comply the AutoIP testing item requirement of DLNA Test Plan.

# --- default gateway
# option routers 192.168.0.1;  << comment out the default router of DHCP advertisement to avoid the client receiver to set the default router in the LAN network
option subnet-mask 255.255.255.0;

option nis-domain "domain.org";
option domain-name "domain.org";
option domain-name-servers 192.168.1.1;

option time-offset -18000; # Eastern Standard Time
range dynamic-bootp 192.168.0.10 192.168.0.100;
default-lease-time 300; << Set lease time as 300 seconds to conform the certification testing requirement
max-lease-time 43200;

Besides, we need to setup the server address of binding network interface in the same network domain as the assigned dhcp address. In our example, we set the server network address as 192.168.0.1 and netmask as 255.255.255.0.

### Start up the DHCP Server
Start the DHCP server
# service dhcpd start
Starting dhcpd: [ OK ]

Show the DHCP server current status
# service dhcpd status
dhcpd (pid 11185) is running...

# netstat -anp | grep 67 | grep dhcpd
udp 0 0 0.0.0.0:67 0.0.0.0:* 11185/dhcpd

Stop the DHCP server
# service dhcpd stop
Shutting down dhcpd: [ OK ]

2008年2月4日 星期一

Linux Service - cvs setup server

CVS Server 利用xinetd dispatch

1. 設定xinetd 的相關步驟, 如果是使用ssh(ext mode)access CVS Server, 應該可以不用, 似乎是使用pserver才需要

首先在/etc/xinetd.d/ 增加cvspserver 檔案
內容如下
service cvspserver
{
disable = no ==> enable the service
port = 2401 ==> cvs listen port
socket_type = stream
protocol = tcp
wait = no
user = root
passenv = PATH
server = /usr/bin/cvs
env = HOME=/var/cvs
server_args = -f --allow-root=/home/cvs/CVSROOT pserver ==> /home/cvs/CVSROOT 為CVS repository directory
bind = 127.0.0.1 ==> cvs listen address
}

注意必須包含有 /etc/xinetd.conf, 如下

#
## Simple configuration file for xinetd
##
## Some defaults, and include /etc/xinetd.d/

defaults
{
instances = 60
log_type = SYSLOG authpriv
log_on_success = HOST PID
log_on_failure = HOST
cps = 25 30
}
includedir /etc/xinetd.d

2. 重新啟動xinetd (由於我在安裝時系統沒有xinetd, 所以我去重新下載了xinetd, 編譯過後, copy contrib/xinetd /etc/rc.d/init.d/ 下成為service script)
/etc/rc.d/init.d/xinetd restart
正在停止 xinetd: [ 確定 ]
正在啟動 xinetd: [ 確定 ]


/home/cvs 的結構如下

ls -la /home/cvs/
drwxrwxrwx 3 root wheel 4096 2008-02-05 13:15 CVSROOT
drwxrwxr-x 6 username username 4096 2008-02-05 13:15 test
drwxrwxr-x 3 username username 4096 2008-02-05 20:42 test2

CVSROOT 目錄必須要讓所有人都可以有寫的權限, 因為cvs server 必須要記錄user 的cvs 行為在CVSROOT 目錄內的檔案中

如何控管CVS Server 的個別權限 (READERS, WRITERS,PASSWD...)
設定Anonymous 的權限
有空再來測試
We can manage the CVS permission by using the Linux file system permission mechanism. For example, you can group some user into a specified group. And only this group can access a cvs project which group id is the same with that user group. So we can simply use the user/group/other file permission to manage the CVS access control.

e.g.
Set the user1, user2 belong in the "cvs"(id: 501) group
# cat /etc/passwd
[omit]
user1:x:500:501:User1:/home/user1:/bin/bash
cvs:x:501:501::/home/cvs:/bin/bash
user2:x:502:501::/home/user2:/bin/bash

// Make user1 and user2 in the cvs group
# cat /etc/group
[omit]
cvs:x:501:user1,user2




3. 如何import 檔案到剛建立好的CVS Server
我的經驗是從其他CVS import 檔案進來, 首先先把原有的目錄中的 CVS/ 子目錄先刪掉(這些檔案是CVS Server 在maintain cvs 的系統檔案, 我們不用把它們upload到新的project當中)

# cd project
project/# find ./* -name CVS -exec "rm -rf {}" \;

cvs import -m "initial" test3 vendor-name main ==> 其中test3是CVS project name, vendor-name 是 branch tag, main (release tag) 是main trunk tag

cvs import -kb -m "initial files" projectName vendorName main ==> import binary files (add -kb will inform the cvs server that all the uploaded files are binary files)

import 過程的log如下
I test3/filename.o ==> ignored files (*.o, *.a..)
N test3/filename.c ==> newAdded files
[omit]


之後再來cvs client 檢查就會發現如下
# cvs st -v Makefile
username@IP-address's password:
===================================================================
File: Makefile Status: Up-to-date

Working revision: 1.1.1.1
Repository revision: 1.1.1.1 /home/cvs/test3/Makefile,v
Sticky Tag: (none)
Sticky Date: (none)
Sticky Options: (none)

Existing Tags:
main (revision: 1.1.1.1)
vendor-name (branch: 1.1.1)


之後就可以利用client CVS 來執行checkouot 該project 來work了

Note:
We can configure the /CVSROOT/cvswrappers as the following setting to separate different file expansion as binary or text file (default configuration)

*.vsd -k 'b' -m 'COPY'
*.CLASS -k 'b' -m 'COPY'
*.DOC -k 'b' -m 'COPY'

In the real CVS data file, like "file.doc,v", will contain the expand tag to record the kflag type. like following examples
head 1.1;
branch 1.1.1;
access ;
symbols main:1.1.1.1 vendor-name:1.1.1;
locks ; strict;
comment @# @;
expand @b@; ==> "b" indicate "binary"



The method of changing the kflag
$ echo '$Id$' > kotest
$ cvs add -kb -m"A test file" kotest
$ cvs ci -m"First checkin; contains a keyword" kotest

If a file accidentally gets added without '-kb', one can use the cvs admin command to recover. For example:

$ echo '$Id$' > kotest
$ cvs add -m"A test file" kotest
$ cvs ci -m"First checkin; contains a keyword" kotest
$ cvs admin -kb kotest
$ cvs update -A kotest
# For non-unix systems:
# Copy in a good copy of the file from outside CVS
$ cvs commit -m "make it binary" kotest