Thursday, October 12, 2006

The power!!!! [getting your Free-BSD installation up and running as FTP & Telnet server]

Yeah well its me again and BSD is taking over slowly and surely. Well this week I got the 101 kids and compilers kids doing labs. lisp, prolog, lex, yacc, over my BSD machine via telnet and ftp. It was so fun. The 101 kids were running 80+ telnet sessions in total and it really cut down the hassle of installing everything on 80 machines because lisp and prolog were only going to be covered in one lab. Anyways here's how I setup everything.

Take PC-BSD / Free-BSD installation. <-- Check out elsewhere on installation tips.
Once its installed, open the console and type in sysinstall and hit enter. This should bring up a utility. Under configuration, hit Network and there enable inetd.

It will also spring up the file from /etc/inetd.conf up for editing. Uncomment the lines for ftp and telnet. [Note telnet is not secure but I used it due to fact that I'm in a trusted environment and they're windows machines everywhere].

You're good to go. Telnet should be operational. In case its not, you can make sure that the packet filter is disabled:-

Iqbal# pfctl -d
pfctl: pf not enabled

In case you want to leave it enabled, go into /etc/pf.conf and configure it.

Once your ftp and telnet servers are up and running, you have to look at user convinience. Install nano, pico and the like (bleh!!!!) from the ports collection. You can get precompiled binaries with the extension .tbz and all you have to do is run them with pkg_install

Once this is done, you're up and ready to go. Well not really. I had to make accounts for my users/students which required some perl scripting. Good old perl eh. :P

use strict;

## create accounts for user_1 .. user_300
for my $n ( 1..80 ) {
    #Phase 1
    system('pw', 'useradd', "101-$n", '-d', '', "/usr/home/101kids/101-$n");
    #phase 2
    system('passwd', "101-$n");
    #phase 3
    system('mkdir', "/usr/home/101kids/101-$n");
    #phase 4
    system('chown', "101-$n", "/usr/home/101kids/101-$n");   
    #phase 5 pw usermod 101-1 -d /home/101kids/101-1
    system('pw', 'usermod', "101-$n", '-d', "/usr/home/101kids/101-$n");   
    #phase 6
    #system('rmuser', "101-$n");   
}

Well theres the magic for you. Uncomment the lines you need. Phase 6 is for undoing everything. passwd will ask for a password everytime. I just held the enter key. I could assume that everyone would change his password on first logon.

Plus you can also  use the following line in the loop to throw some examples and stuff in.

    #system('cp', 'knowledge.pl', "/usr/home/101kids/101-$n/grandfather.pl");

Remember to also give ownership to the files you copy as root as follows:-

    #system('chown', "101-$n", "/usr/home/101kids/101-$n/grandfather.pl");   

I just cant wait till the weekend when I shall delete the folders of 22 compiler kids + 160 101 kids work. Which means 3.5 hours each which all amounts to 637 hours. This shall be fun indeed.

Wednesday, October 04, 2006

Samba Server giving me the creeps

 Getting samba to work. Sometimes it so happens that you get everything done, you have samba.conf configured correctly and it still doesnt work. It was giving me timeouts when I tried to access my PC. In my case I installed webmin and a whole lot of other products so I dont know if any of those messed up with my system but the following should be of use hopefully if you are having windows problems.

My samba was giving me timeouts when I tried to. First of all you can analyse the socket connections on your PC using a command called netstat. (For those of you who are unfamiliar with grep, it is a simple pattern matcher. Just like find in the results)

Iqbal# netstat -an | grep 139
tcp4       0      0  *.139                  *.*                    LISTEN

My Samba server is listening here so it means that it must be working normally.

If this entry is missing, you need to make sure of the following things. First of all if the BSD packet filter is enabled or disabled

The following command is for disabling your packet filter.

Iqbal# pfctl -d
pfctl: pf not enabled


In case you want to leave it enabled, go into /etc/pf.conf and you can set it to allow all packets by uncommenting(or typing):-

pass in all #which in essence isnt far from disabling

or you can use an entry of the sort:-

#pass in on $ext_if proto {tcp, udp } all from any to $ext_if port 139 keep state     

Remember port 139 is the default listening port for samba servers.

If this is still not the problem, it is possible that your samba daemon (located @ /usr/sbin/smbd ) may not be starting.

Change to superuser by typing su, hitting enter and supplying your root password.

Once su, head run the smbd binary with the following usage:-

/usr/sbin/smbd -D

Now check if you can access yourself from Konquerer or using smbclient on Konsole.

This worked for me. However all does not end here. In order to autostart it, I placed the following two lines in rc.local :-

# Start Samba Server
/usr/local/sbin/smbd -D

Now your PC-BSD installation should autostart samba server automatically as it did for me.

inetd.conf can also be configured to start samba server by uncommenting the following two lines:-

netbios-ssn stream tcp  nowait          root    /usr/local/sbin/smbd    smbd
netbios-ns dgram udp    wait            root    /usr/local/sbin/nmbd    nmbd

However this approach although more elegant, wasnt working for me.

Note: Suggestions, comments and healthy criticism will be most appreciated. In fact I'm looking for people to help make this blog successful so I have no problem in sharing ownership.

Regards,

Iqbal Talaat Bhatti

Monday, October 02, 2006

Intro to my BSD Blog

Okay people here goes. Well most of you guys probably know that BSD is really a remarkable line in *NIX Operating Systems. Yahoo uses BSD machines in the background. Solaris, Mac OS Darwin, and various other BSD's e.g. Free BSD, NET BSD, OpenBSD, etc are derived from here. Its strong points are security, stability and they do things in a really organized manner. BSD has a more stable file system and a better Network Stack. I wont go on about the pros and cons about Linux and BSD, I expect you guys to Google for it.

However FreeBSD features the following mechanism:-
  1. Installation from source /BSD
  2. Installation from Linux Source using the ports(maintained in /usr/ports/) collection. Ports basically contain files containing information on how to compile a particular source highlighting the differences. i.e. on line l do this instead of this. You can read more on this in the FreeBSD handbook . The list of FreeBSD ports is availible here.
  3. You can run BSD binaries as well as Linux binaries. The motivation behind this is to enable BSD to run commercial applications developed for LINUX that were made availible in the Binary Format.
  4. I'm using PC-BSD. I can download and installed .pbi files just like you can install .msi installers on windows. Expect these files to be huge. e.g. 70-80 Megs for KOffice. You can find .pbi files at pbidir. You have uninstallers installed as well and you can list and remove installed pbi's just like using add/remove programs under windows.
* Note : PC-BSD was rated as the most user-friendly OS for beginners by osweekly.

Well now that we've finished an informal introduction about BSD, I'll come over to the main purpose of this blog. This blog is mainly intended to spread information and facts about BSD, document the problems I face and their solutions just so that knowledge can be spread in a more efficient manner over the internet. I would use a website but Blogging does all the formatting for you.

Best of Luck and Happy BSD'ing