Posts Tagged ‘freebsd’

How to Create User with useradd in FreeBSD

Friday, July 9th, 2010

You can invoke “adduser” command in FreeBSD in order to create new user. Adduser will prompt you for user info like name, uid, gid, shell environment and etc. But sometime we would like to create user access through Bash script. “useradd” command is the good way to do it.

In Linux, using “useradd” is pretty common for creating new user access. You can also use “useradd” in FreeBSD, but not directly invoke “useradd” command. Below is the sample of creating new user in FreeBSD with “useradd”.


shell> pw useradd cheryl -c 'Cheryl Windows Admin' -d /home/cheryl -s /usr/local/bin/bash

New user account is created, but don’t forgot to set password for the account


shell> passwd cheryl

You can run other command like “userdel”, “usermod”, “usershow”, “groupadd”, “groupdel”, “groupmod”, “lock”, “unlock” on FreeBSD by using the “pw” command.

Razor2 Error: No such file or directory report requires authentication

Tuesday, July 6th, 2010

While doing Spam Report on SpamAssassin, I came across this error message,


reporter: razor2 report failed: No such file or directory report requires authentication at /usr/local/lib/perl5/site_perl/5.x.x/Mail/SpamAssassin/Plugin/Razor2.pm line 180. at /usr/local/lib/perl5/site_perl/5.x.x/Mail/SpamAssassin/Plugin/Razor2.pm line 330.

I checked the file existed, so It’s something to do with Razor authentication. This is what you need to do fix the error message from SpamAssassin.


shell> razor-admin -create
shell> razor-admin -register

Upgrade to php52 on FreeBSD

Friday, July 2nd, 2010

By default, after portsnap to latest FreeBSD port tree, it will upgrade your php5.2 to php5.3 automatically. There isn’t any option where you can to remain your PHP version to 5.2.

In order to keep my PHP applications running on PHP version 5.2, what I did is upgrade all php5-* packages to php52-*, but it will be a little waste of time if doing it manually, port by port.

So I written this simple bash to output me the packages of php5-* which need to upgrade to php52-*


for d in `portversion -vL= | grep php5 | awk '{print $1}'`; do  OLD=`echo $d | cut -d - -f 1,2`; NEW=`echo $d | sed s/php5/php52/ | cut -d - -f 1,2`; THEPATH=`whereis $NEW | awk '{print $2}' | cut -d / -f 4,5`; echo "portupgrade -o $THEPATH $OLD && \\"; done

The bash will actually output


portupgrade -o textproc/php52-simplexml php5-simplexml && \
portupgrade -o devel/php52-spl php5-spl && \
portupgrade -o databases/php52-sqlite php5-sqlite && \
portupgrade -o devel/php52-tokenizer php5-tokenizer && \
portupgrade -o textproc/php52-xml php5-xml && \
portupgrade -o textproc/php52-xmlreader php5-xmlreader && \
portupgrade -o textproc/php52-xmlwriter php5-xmlwriter && \
portupgrade -o archivers/php52-zip php5-zip && \
portupgrade -o archivers/php52-zlib php5-zlib && \

Before upgrading the php extensions package, upgrade your php52 as below


portupgrade -o lang/php52 php5

On the last time, remember to remove “&& \”, or you can press enter key twice to activate the upgrade.

Bind Error: “max open files (3520) is smaller than max sockets (4096)”

Monday, June 28th, 2010

Just notice one of the DNS server has the error message


28-Jun-2010 16:28:24.283 general: max open files (3520) is smaller than max sockets (4096)

It’s something to do with kernel setting, on FreeBSD, configure the following


shell> sysctl kern.maxfiles=4096
shell> sysctl kern.maxfilesperproc=4096

Alternatively, put the above configuration on /etc/sysctl.conf in order to configure it at start up level.

Change or Set User Password in FreeBSD

Friday, June 4th, 2010

If you notice, during FreeBSD installation, it doesn’t have a step by step installation guides for creating user’s password for login credential. By default, FreeBSD installation only come with user “root”, and it doesn’t prompts for password setting for default user “root”. After installation, you can login to FreeBSD with user “root”, no password.

So, it’s advise that to set user’s password after installation. You can set or change user’s password in FreeBSD with passwd command.

Try to have your password in alphanumeric combination, meaning alphabets + numbers and at least 6 characters long. You can do some creative password combination like “go2HELL”, “1amN00b1nUn1x”, “BUYm3b33r”, “h3ySumm3rH0t” and etc. Please do remember, the password is case sensitive too.

To Set Password for Default User “root”

To set the password;

  • type: passwd
  • input your password twice

To change your password, use the same command and it will prompt you for current password before putting the new one.

To Set or Change Password for Other Userid

Login as “root” and change user’s password, in example userid foo

  • Type: passwd foo
  • Input your password twice