mount error(12): Cannot allocate memory

Sometimes when connecting to the Windows shared drive using the Linux/Windows system, we get the error as below:-

[[email protected] ~]# mount.cifs // /mnt/ -o username=myuser,password=123456
mount error(12): Cannot allocate memory
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

This error means that we are not able to allocate memory on the source server (which you're trying to connect to) and somehow we need to be able to increase the memory on the server. This error actually needs 3 changes to be done on the source server in order to connect to the Windows shared drive:-

1) Increase the system cache for sharing large files in the registry.

Open regedit and set

“HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\LargeSystemCache” to “1".

2) Give priority to file sharing over reducing memory usage.

Open regedit and set
“HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\Size” to “3".

3)  Check if the IRPStackSize registry entry exists and increase the IRPStackSize value on the server.

Open regedit
Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters

Click IRPStackSize, click Edit, and then click Modify and then in the Data Value box type a larger value and now click OK to apply this larger value.

If the IRPStackSize entry is not present in this subkey :-

Click Edit, point to New, and then click DWORD Value. Type IRPStackSize, and then press ENTER.

Click IRPStackSize, click Edit, click Modify and then in the Data Value box type a larger value, and then click OK.

Then restart the “server” service or if it is possible to do so, reboot to apply the above changes on the Windows system.

That's all that needs to be done on the Windows server. Now try again to connect with the shared drive/directory/partition and you'll have success.

Sachin | Wednesday 26 February 2014 - 11:34 pm | | Default | No comments

Connecting PHP with the MSSQL database on IIS7

Sometimes we have to connect PHP with MSSQL - most of the webhosts don't offer this on a shared environment but it is possible to have this facility on a dedicated server or VPS with the following steps:-

Step 1: Make sure that you're running the IIS web server with PHP installed on it.

Step 2: Download Microsoft Drivers 3.0 for PHP and the SQL Server on your server and run the file:-

Step 3: When prompted, enter the path to the PHP extensions directory - it's recommended by Microsoft to use 'C:\Program Files'

Step 4: After extracting the files, copy the dlls from the extracted directory

(For non-thread safe)

(For thread safe)

to the PHP extensions directory which could be like C:\PHP\ext\ or 'C:\Program Files x86\PHP\ext\' on the server.

Note: Read the Installation section of the SQLSRV30_Readme.htm file for more details.

Step 5: Install the Microsoft SQL Server native client as per your MSSQL edition - 2005 or 2008 or 2012.

Step 6: Enable the sqlsrv extension in the php.ini configuration file of the server, as below:-


Step 7: Then restart the web service or IISRESTART on the server, and then check the phpinfo page and you should be seeing that the sqlsrv section is now being displayed on that page which means that you are now able to connect with the MSSQL database using PHP code.

That's all.

Sachin | Sunday 23 February 2014 - 06:35 am | | Default | No comments

Disabling the default SSH port and direct root user login on the Linux machine

Many times, a hacker tries to login directly via root access on the Linux machine (which enables root login) and can get access by cracking the password with the default SSH port.

Today we'll discuss how to change the default SSH port and to disable direct root login on the remote Linux machine via SSH. This is all done with the help of SSH (Secure Shell).

Follow the steps below:-

Step 1: Login onto the Linux machine.
Step 2: Open the SSHD configuration file at the location below:-

vim /etc/ssh/sshd_config

Step 3: Find the commented settings below and do the changes as below:-

#Port 22

Port 9899

#PermitRootLogin yes

PermitRootLogin no

Step 4: Save the file and restart the SSHD service using the command below:-

service sshd restart

and that's it. You've secured your Linux machine/server by using SSH on its default port and with the root user.

After this, make sure you've created another normal user account with which you can use SSH on the Linux machine and after that take shell of the root using the su - command and with the root password.

This will make your system more secure.

Sachin | Saturday 22 February 2014 - 06:31 am | | Default | No comments

How to use diff and patch

We'll learn the three things below, as follows:-

1) Differentiating between two files and redirecting the differences into a new file.
2) Creating a patch file with the diff command utility.
3) Updating the file with patch.

diff => diff is a Unix utility showing the difference between two files which are almost similiar by virtue of their contents.

patch => patch is a Unix utility which is used for applying the differences between two files to make them similiar or the same by virtue of their contents.

1) With the diff command utiliy we can show the difference between two files on the screen or can also redirect them into a file which will create a patch for making the target file the same as the source file.

i) To get the output on the screen between two files, use the command:-

diff abc_file.txt xyz_file.txt

ii) To redirect the difference between two files into one file, use the command below:-

diff abc_file.txt xyz_file.txt  > diff_file.txt

2) Now, creating a patch file with the diff command utility is as below:-

diff -uN orig_file new_file > patch.orig_file

3) Applying the file with patch

patch -u new_file patch.orig_file

and then when you check new_file, it'll have all the changes done and it'll have the same contents as orig_file.txt.

Using and applying a patch is the quickest way to do many changes with just one command, when you need to change multiple files for the same changes. That's all.

Sachin | Monday 10 February 2014 - 12:24 am | | Default | No comments

Password-less SSH authentication to a remote machine

If you're getting irritated or tired of giving your password again and again during SSH login to a remote host, then there is another way using which you can do SSH access to the remote host: RSA/DSA key-based authentication.

For this you'll need to create the RSA/DSA-based public/private key on the source host and save that key on the remote host so that whenever you do SSH access from the source host, the target host will authenticate you on the basis of the key you stored.

Below is the way using which you can create and store the key on the remote host and then do password-less SSH access to the remote host.

Step 1: Create the SSH key on the source host using the command below:-

ssh-keygen -t rsa
Generating public/private RSA key pair.
Enter the file in which to save the key (/root/.ssh/id_rsa): [press enter]

Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):  

-> Above that, it'll prompt you for entering the passphrase. So either enter your passphrase or just press enter.

Enter the same passphrase again:
-> You will be prompted again to enter the passphrase.

Step 2: Use the command below to save the private key on the remote host:-

ssh-copy-id -i ~/.ssh/ remote-host

It'll prompt you for the password of the remote host in order to save the key on the remote host - and that's it.

Step 3: Now, try to do SSH access on the remote host using the command below:-

ssh remote-host

Ex- ssh [email protected]

and you'll be directly entered into the remote host without being prompted for the password.

So, this way you can login onto the remote host without a password.

Sachin | Wednesday 05 February 2014 - 05:17 am | | Default | No comments

Argument list too long? Deleting the file or directory using its inode number

We've noticed that sometimes a file or directory has a really big size due to which removing it is not possible
and you get the message below:-

Argument list too long \*

This issue certainly happens with everyone and especially with the folder "Session", where all the sessions of the server in a directory are kept. Recently I've faced this issue on an Linux server where the user stores the server's sessions files at the location below:-

[[email protected]]# pwd
[[email protected] lib]# cd /var/lib/
[[email protected] lib]# ls -al
drwxrwxrwx.  4 root  root  32875698 Nov 22 15:20 session

And I tried every possible way to remove the files inside it with the following commands:-

rm -rf session/*                                                    (remove all files inside the session directory)
find session/ -type f -name "*.sess" -exec rm {} ;      (removing files whose names end as .sess)
find session/* -mtime +50 -exec rm {} \;                 (removing files 50 days old)

But all give the same output as below after 1 hour:-

Argument list too long \*

At last, I tried the way which did remove the directory very quickly for me. I used the help of its inode number.

Step 1: Check the inode number of the directory using the command below:-

[[email protected] lib]# ls -li

1179686 drwxrwxrwx. 4 root  root  32875698 Nov 22 15:20 session

Above the first number, i.e. 1179686, is the inode of the directory session. Now remove the directory using the inode number with the command below:-

[[email protected] lib]# find . -inum 1179686 -exec rm -rf {} \;

"No such file or directory."

And that's it! The directory will be removed and after a few seconds you'll get the message as above. That's all!

Sachin | Monday 03 February 2014 - 10:18 pm | | Default | No comments