How to Create User with useradd in FreeBSD

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.

Install and Configure mod_suphp or suphp on Plesk Server

Plesk control panel comes with Media Temple DV package doesn’t support suphp/mod_suphp. I like suphp, it gives you the user/group permission as the control panel created for you, so that you will have the permission to read/write on your own files/folders.

I mentioned before that I got Dedicated Virtual (DV) VPS package from Media Temple previously. It has been a while since I subscribed with Media Temple. So far I am happy with their services and I have moved my blog over to Media Temple 2 months ago. Since then I never bother to patch my WordPress until Version 3 released, mainly was because I am too lazy to download, backup, untar, copy over for upgrade. I prefer the One Click WordPress Upgrade option, yes.. That’s how Lazy I am!

I just had mod_suphp installed on my Plesk, and first thing is I did was upgraded my WordPress to Version 3, well also all my plugins. Here is the how-to of suphp installation and configuration on Media Temple Dedicated Virtual package.

First, install mod_suphp from yum


shell> yum install mod_suphp

After installation, you should see suphp configuration files located at
/etc/httpd/conf.d/mod_suphp.conf
/etc/suphp.conf

On mod_suphp.conf, you can refer to the configuration I have below;


LoadModule suphp_module modules/mod_suphp.so
suPHP_AddHandler php5-script
suPHP_Engine on

You will notice that the Handler is php5-script, it’s the php’s handler configured on Plesk, so we will not disturb that. You need to make the handler recognize on suphp, and follow the configuration for /etc/suphp.conf


[global]
;Path to logfile
logfile=/var/log/suphp.log

;Loglevel
loglevel=info

;User Apache is running as
webserver_user=apache

;Path all scripts have to be in
docroot=/var/www/

; Security options
allow_file_group_writeable=false
allow_file_others_writeable=false
allow_directory_group_writeable=false
allow_directory_others_writeable=false

;Check wheter script is within DOCUMENT_ROOT
check_vhost_docroot=true

;Send minor error messages to browser
errors_to_browser=true

;PATH environment variable
env_path=/bin:/usr/bin

;Umask to set, specify in octal notation
umask=0022

; Minimum UID
min_uid=500

; Minimum GID
min_gid=500

; Use correct permissions for mod_userdir sites
; handle_userdir=false

[handlers]
;Handler for php-scripts
x-httpd-php="php:/usr/bin/php-cgi"
php5-script="php:/usr/bin/php-cgi"

;Handler for CGI-scripts
x-suphp-cgi=execute:!self

After restart apache services, all your website hosted on the server will have suphp support, you might want to check all the permission of your files and folders before restart apache. Make sure the folder is mod is 755 and file mod is 644.

You can do the quick mod change with find command


shell> find /var/www/vhost/domain-name/httpdocs/* -type f -exec chmod 644 {} \;
shell> find /var/www/vhost/domain-name/httpdocs/* -type d -exec chmod 755 {} \;

That’s it! mod_suphp on Plesk. Nice and Clean.

Razor2 Error: No such file or directory report requires authentication

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

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)”

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.