Secure remote copy with scp

September 8, 2014

For copying files between different hosts from console, scp is your first choice, since it uses commonly used ssh1 protocol, that will be available on (almost) any machine.

The structure is like this:

scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] [

[user@]host1:]file1 … [ [user@]host2:]file2

Short example: if you want to copy some file from current host to a remote host your command will be like this:

scp -p /home/user/yourfile.tgz   user:pass@remotehost:/home/someuser/your_directory/

where -p = preserve file properties (modification time, modes, etc.)

if want to copy all files and subdirectories in a folder for example you will need to add -r , which stands for recursive copy

scp -rp /home/user/somedirecory/*   user:pass@remotehost:/home/someuser/your_directory/

I will not describe all the parameters here, for a complete description you can read the man page here: http://linux.die.net/man/1/scp 

Usually ssh is listening on port 22, and if your hosts ( source or destination) are listening on the standard port, you do not need to specify it, but if any of the hosts is configured to listen on some other port ( usually for increased security reasons ), then you must specify it with -P ( notice that is capital P, since p is reserved for “preserve properties” from rcp command )

scp 

scp -P 2222 -r user:pass@remotehost:portnumber/home/someuser/source_directory/*  /home/user/

 

, or as an alternative you may specify the port at the end of the url, separeted by : , like you would do on ftp login

scp -p /home/user/yourfile.tgz   user:pass@remotehost:portnumber/home/someuser/your_directory/

 

Hope this is useful for those searching for a quick remote copy solution.

Yes to all for recursive commands in linux

July 2, 2013

Today I ran into a strange problem:

On centos cp command is “-interactive” by default:

cp  -i, –interactive  -   prompt before overwrite

I had to copy a large folder with lots of subfolders onto another folder, overwriting all duplicate content.

Normally you do that with:

$ cp -rf folder1/* folder2/

forcing with -f to overwrite, and making it recursive with -r

The problem!

The problem was that on centos cp is -interactive by default, I had to press y -> enter a thousand times, which is not very pleasant.

The solution?  the yes command! yes, it’s true, there is a yes command, beautiful.

Usage: yes [STRING]...
 or: yes OPTION
Repeatedly output a line with all specified STRING(s), or `y'.
    --help display this help and exit
    --version output version information and exit

All you need to do is prepend command yes “yes” to your script or command. Of course is useful for recursive deleting files or other actions you may need

$ yes “yes” | your_command

$ yes “yes” | script

In my case, the solution was:

$ yes “yes” | cp -rf folder1/* folder2/

 

And it worked like a charm.

 

 

Cpanel – Forward email to multiple addresses

March 27, 2009

I was recently facing a very simple problem regarging on how to forward an email address to multiple adresses in cPanel.  As easi as it seemed it should be, I was not sure if the result I get with the new Cpanel 11 will be what I espected.

I wanted to redirect aliasemail@mydomain.com to  realmail1@anotherdomain.com and secondrealmail@anotherdomain.com .

Normaly, in linux a configuration file I would add the multiple forwarded adresses with a comma between them, and everything would work fine, but, since cPanel updated to version 11, it introduced a new user interface with lots of error checking.  And so, if you try to enter two email adresses into the forwarder address box, the box will turn red and notify that ” ; ” or ” , ” are not acceptable characters.

So the dilema is: what shoul I do ? add 2 forwarders ? will this work as espected ?

The answer is yes, we have to add 2 forwards

aliasemail@mydomain.com to  realmail1@anotherdomain.com
and
aliasemail@mydomain.com to secondrealmail@anotherdomain.com

This actually creates a single forward entry within the operating system, but cPanel keeps it recorded as two separate fowards.

Hope this is useful to you.

Calin

PHP Email Headers – PHP Mail Function headers

September 2, 2008

PHP Mail Function headers

Headers are the parts seen at the top of emails. Typically :

To : A comma seperated list of recipient emails.
From : The senders email address.
Reply-To : The email address where replies should be sent to.
Return-Path : Kinda the same thing as the Reply-To. Some email clients require this, others create a default.
Subject : Subject of the email.
CC : Carbon Copy. A comma seperated list of more recipients that will be seen by all other recipients.
BCC : Blind Carbon Copy. A comma seperated list of more recipients that will not be seen by any other recipients.

The TO and SUBJECT filds are the first and second variables in the MAIL command. The extra headers seen above can be entered as a 4th variable in the MAIL command.

<?php
mail(“yourplace@somewhere.com”,”My email test.”,”Hello, how are you?”,”From: myplace@here.com\r\nReply-To: myplace2@here.com\r\nReturn-Path: myplace@here.com\r\nCC: sombodyelse@noplace.com\r\nBBC: hidden@special.com\r\n”);
?>
Looks kinda messy when it’s all in there without using variables. That above example has all of the extra headers being declared. You may specify all or some or none as you desire. There are 2 very important things to note here :

1. These headers need their NAMES: shown unlike the first three variables in the mail command. The header names are CaSe SeNsItIvE. Use per example.
2. Each header is ended with the Return and Newline characters. \r\n There are no spaces between each header.

For better organization, these extra headers can be declared in a variable string like our previous examples.

<?php
$to = “yourplace@somewhere.com”;
$subject = “My email test.”;
$message = “Hello, how are you?”;

$headers = “From: myplace@here.com\r\n”;
$headers .= “Reply-To: myplace2@here.com\r\n”;
$headers .= “Return-Path: myplace@here.com\r\n”;
$headers .= “CC: sombodyelse@noplace.com\r\n”;
$headers .= “BCC: hidden@special.com\r\n”;

if ( mail($to,$subject,$message,$headers) ) {
   echo “The email has been sent!”;
   } else {
   echo “The email has failed!”;
   }
?>

I forgot the root password on my linux machine

May 12, 2008

Linux basic commands FAQ

Simple tasks for simple minds :)

The “forgotten root password”

Q. I forgot the root password on my linux machine. How do I change the password ?

R. The easiest way to change the “forgotten root password” is to boot your Linux machine in the single-user mode, namely at the “lilo”prompt, during the bootup you will type:

linux single

This will log you in as “root” without asking for a password. As root, you may now change the root password using passwd command ( the old password is not required ):

passwd

If this seems to you insecure or to simple to be true, that is because no computer system is realy secure if other people have physical access to the computer hardware.

There is a way to secure the lilo boot, but this will be the subject for another article.

Linux change root password

May 12, 2008

Linux basic commads FAQ:

Simple task for simple minds :)

Q. How do I change the root password on a linux ( unix ) operating system ?
 
R. What you need to do in order to change the root account password on a linux or unix machine is:
 
- open a terminal an login as root ( if the system permits loging in as root )
or
- open a terminal, login with your account and type “su” to become root.
Enter the ( old ) root password to login
then type “passwd” and it will prompt you for a new password.
—————————-
 
root@ibm:/# passwd
 
Changing password for root
Enter the new password (minimum of 5, maximum of 127 characters)
Please use a combination of upper and lower case letters and numbers.
 
New password: **********
Re-enter new password: **********

Password changed.
 
————————–

 

This should be all.
P.S. The password should be rather complex, containing numbers and letters. However try to pic one that you will remember easily, but not known by everybody.

 

Linux TAR Command

April 4, 2008

Quick Start: Here we’l present quick start examples explained.

Create linux tar gz (Gzip) archive

tar -czvf myarchive.tgz mydirectory/

We use the -t option to create an linux tar archive
-c, –create create a new archive

Note that .tgz is the same thing as .tar.gz

Create linux simple tar archive (withouth compresion)

tar -cvf myarchive.tar mydirectory/

Extracting linux tar archive:

Extract linux tar gz (Gzip) archive
tar -xzvf mystuff.tgz

Extract linux simple tar archive
tar -xvf mystuff.tar

We use -x to extract the files form the tar archive
-x, –extract, –get extract files from an archive

Extract linux tar archive to speciefied directory
tar -xvzf filename.tar.gz -C /desired/path

And now let us shortly explain this command

Usage: tar [OPTION]… [FILE]…

Let us check the option used in this example

-c, –create                      create a new archive
-z, –gzip, –ungzip        filter the archive through gzip
-v, –verbose                   verbosely list files processed
-f, –file=ARCHIVE          use archive file or device ARCHIVE

-C directory file
Performs a chdir  operation on directory and performs the c (create) or r (replace) operation on file .
In c and r mode, this changes the directory before adding the following files. In x mode, change directories after opening the archive but before extracting entries from the archive.

Testing / viewing your archive

tar -tvf myarchive.tar
tar -tzvf myarchive.tgz

Here we used the – t opton
-t, –list                           list the contents of an archive

————————————————-

Go ahead, try out these commands and stay tuned; we will come up with more doccumentation on linux tar command

Why basic Linux Commands ?

April 3, 2008

So, Why basic Linux Commands ?

Because I for one, am not a Linux or UNIX guru, and still need to use Linux and Linux basic (or not so basic) commands.

So I decided to gather all the articles about simple Linux and UNIX commands, in one place. linuxbasiccommands.wordpress.com will be the place for there articles. Stay tuned, I will update frequently.

I am also a PHP programmer and web designer, and live in the city of Brasov, Romania, in the well-known  Transilvania region  ( Transylvania in english ).  Although this blog is not about my city or my country, knowing where I am from might tell you something about me.

I am working on some Romanian travel websites, and also hosting it on my own server, so this is where the need for knowing some basic Linux came from.

Recently one of theese websites,  www.Romania-turistica.ro, was  penalized by Google for having unnatural links posted in this blog, but the thing is that working on  these sites and hosting them on my own server  are exactly the reasons I needed to learn some basic Linux and thus the reason I started this blog. The link is posted now with no follow rel attribute, so I do not get a Google penalty again.

This being said you are welcome to visit my Linux blog and I will be happy if you will find any information useful . Feel free to comment or ask a question, I will do my best to give a good  answer.


Linux basic commands

The simple and basic linux commands, explained for dummies.

Tourism in Romania

Great places to visit in Romania. Bred and Breakfast, Lodging, Guest houses and Hotels.

Info Predeal

Info - Cu, Din si Despre Predeal

Optimizare Seo

Loc de joaca si discutii despre optimizarea siturilor pentru Motoare de Cautare, cu ridicare la fileu a intrebarii: Optimizare SEO sau Optimizare pentru Utilizatori Umani ?

Follow

Get every new post delivered to your Inbox.