Ramblings from MostlyChris

Tech stuff and a bit more

Browsing Posts in Linux

I recently had to create a number of home directories from the user accounts in the /etc/passwd file because Webmin didn't create them when the user was created. Don't ask me why. Webmin is a mystery and only does things it feels like doing at the time it does them. But I digress..

The first thing I did was to create file with all users that have directories.

cat /etc/passwd | sed 's/:/ /g' | awk '($5 ~ /\//) { print $1 " " $5}' > file.txt

Edit the file you created and remove things like the postfix directory and other non-user account directories.

Next, run the command to create all of the home directories and then change their ownership to the user.

while read line; do mydir=`echo $line |awk '{print $2}'`; myuid=`echo $line| awk '{print $1}'`;  mkdir $mydir 2>/dev/null; chown $myuid:$myuid $mydir; done < file.txt

If you run into semaphore issues….

First, determine the number of semaphores in use.

ipcs | wc -l

Then determine the current settings in the kernel for the number of semaphores.

cat /proc/sys/kernel/sem

Look at the 4th field. It shows the maximum number of shared memory segments for the entire system. If your number of semaphores in use is higher than this number, you will need to increase it. You do this in increments of 128. For example, if your ipcs output is 267 and your kernel settings are '384 64000 64 256' then you have exceeded the number of available shared memory segments.

Add increments of 128 to each of the numbers to exceed what the system is currently using. In this case, you can just add 1×128 so your new values would be: '512 64128 192 384'.

Edit /etc/sysctl.conf and look for "kernel.sem=". Add your new values here, replacing what is here (or better yet, comment the line and add a new one with the new values).

Once you have added this, all you have to do (on a Redhat box) is to issue

sysctl -p

in order to use the new values.

If you would like to verify that the key and the certificate match you need to compare the modulus in both of the key file and the certificate file. You can check for differences in the modulus rather easily by sending the output of the comparison command to 'uniq'. If anything shows up, the numbers don't match and that means that the key and certificate do not match.

The command:

$ (openssl x509 -noout -modulus -in server.pem | openssl md5 ;\
openssl rsa -noout -modulus -in server.key | openssl md5) | uniq

SSH Tunnel

No comments

You can access ports on a remote server and map them to a port on your local computer with an SSH tunnel. I do this with the command:

ssh -N -L localport:127.0.0.1:remote_port user@remote_host

I was installing APC on a server and ran across this error:

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 92160 bytes) in /usr/share/pear/PEAR/PackageFile/v2/Validator.php on line 1831

One would assume that fixing this would be to edit the php.ini file and change the memory settings. However, that is not the case here. In order to fix this, you would edit /usr/share/pear/pearcmd.php and add the following line to the very top of the file (after the opening PHP tag):

@ini_set('memory_limit', '16M');

Adjust the memory limit to what you need. For good measure, I remove that line once I am done installing whatever it is I need to install.