Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Friday, October 26, 2018

How to configure ssh login with out password in Mac OS X and Linux


When ever we want to connect to remote server (or) host using SSH we will provide the host name after it prompt for password. If we follow the below step it won't ask for the password on each time.
ssh password less login


STEP 1 - Generating the key pair

Create your set of keys:
Start up the Terminal application and run:
ssh-keygen -t rsa -b 4096



STEP2 - Copy Generated public to our remote server


Copy the newly created public key to the SSH server(s) you need to auto login into by using your favourite transport method.

Please be careful not to overwrite ~/.ssh/authorized_keys if it already exist! This is how I personally copy the key, might not be your preferred method:

If authorized_keys exist:
cat ~/.ssh/id_rsa.pub | ssh username@example.com "cat - >> ~/.ssh/authorized_keys"
If authorized_keys does not exist:
scp ~/.ssh/id_rsa.pub username@example.com:~/.ssh/authorized_keys


Check your file permissions. A lot of different *nix system is picky when it comes to permissons. Setting your .ssh directory to 0700 and .ssh/authorized_keys to 0600.

  chmod 0700 ~/.ssh
  chmod 0600 ~/.ssh/authorized_keys

Thursday, September 7, 2017

PHP popen() Function

popen in php

Parallel processing in PHP Using popen() Function


Since PHP does not offer native threads, we have to get creative to do parallel processing.
There will be scenarios where PHP takes much time to complete a task. Example scenarios are attaching a large file and and sending an email, or processing a large video file 
to make thumbnails. Imagine  a user having to wait until PHP finishes the all that job.

All the heavy work might being going on at the server. 
But, if a user doesn't see any activity on a page for some time, they might think that the page is not working and leave the page.  In such cases, we can make use of a background process.


Example of popen as a Async processing


Make popen as synchronous

The below code will wait until child process completed.
echo date("h:i:s");echo "\n";
$ph = popen('php ' . $commandName , 'r') or die($php_errormsg);
while (! feof($ph)) {
$s = fgets($ph) or die($php_errormsg);
}
pclose($ph) or die($php_errormsg);
echo date("h:i:s");echo "\n";

Friday, January 13, 2017

Create Ftp User

How to create a FTP user with specific /dir/ 

1. mkdir /var/www/mydomain.com
2. mkdir /var/www/mydomain.com/html
3. useradd <-username>
4. passwd <-username>
5. chown –R <-username> /var/www/mydomain.com



Set the home directory of the user with the following command

usermod -d /var/www/html/ ftpuser

Monday, February 22, 2016

Add text at the beginning of a line in vim

The substitute command can be used to insert (or replace) text. Some examples:

:s/^/new text / Insert "new text " at the beginning of the line.
:s/$/ new text/ Append " new text" to the end of the line.
:s/green/bright &/g Replace each "green" with "bright green" in the line.
By default, each command operates on the current line. If you visually select some text before entering the command, it will operate on each line in the visual selection. See Search and replace for details.
Or you can insert a range immediately after the colon, for instance :.-5,$s/ etc. to substitute from 5 lines above the cursor to the end of the file.

:s/^/test /  ----insert "test" at the beginning of each line.
:%s/^/test / --- insert "test" at the end of each line .

Saturday, February 6, 2016

Delete Files Older Than x Days on Linux

find /path/to/files* -mtime +5 -exec rm {} \;
ex: find /opt/test/patch/* -mtime +7 -exec rm {} \;

The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.
The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days.
The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.