SCP file transfer between two linux machine in command line

SCP (Secure Copy) is a command line tool for Linux systems to securely transfer files from local to remote server or vice a versa. SCP uses SSH protocol for transferring files between two systems which is more secure than ftp.

Syntax: (Local to Remote)

scp /path/to/local/file.txt user@192.168.10.100:/remote/path/

Syntax: (Remote to Local)

scp user@192.168.10.100:/remote/file.txt /path/to/local/

SCP command required password of remote system. In case you need to configure scp command in script and run with scheduler, you need to configure key based ssh login.

Transfer File Local to Remote Server
Following command will copy myfile.txt from current directory of local system to remote server’s /opt directory using root authentication. We are assuming remote server hostname is example.com.

$ scp myfile.txt root@example.com:/opt/

Transfer File Remote Server to Local
Following command will copy /opt/myfile.txt from remote system to local system’s /opt directory.

$ scp root@example.com:/opt/myfile.txt /opt/

Define Port with SCP Command
In case SSH is running on different port on remote server, use -P switch followed by port number with scp command.

$ scp -P 2344 myfile.txt root@example.com:/opt/myfile.txt

Transfer Directory Local to Remote Server Recursively
Following command will copy /opt/mydir directory from local system to remote system’s /opt directory recursively.

$ scp -r /opt/mydir root@example.com:/opt/

Transfer Directory Remote Server to Local Recursively
Following command will copy /opt/mydir directory from remote system to remote system’s /opt directory recursively.

$ scp -r root@example.com:/opt/mydir /opt/

Advertisements

Break Root Password

How to break root password in Linux (RedHat/CentOS)

Its actually very easy to break a linux server’s root password if you have access to the physical server. Security is actually an illusion, just you need to make your server secure from any kind of threat that is coming from your environment and also your friends.

Here i will describe how to break a linux server’s password in a easy way, if you anyhow forget your root password it can be recovered just some few steps and commands. lets begin…

Step-1: Reboot your system by hard switch or pressing ‘Ctrl+Alt+Del’ or any other way you want. And don’t allow your server to load the OS again, i mean before loading just press arrow keys.

Step-2: Now you need to edit the current entry by pressing ‘e’ button. It will open some scripts in your window.

Step-3: Find the line that starts with ‘linux16’ and navigate your cursor to the end of the line. You can do this by pressing the ‘End’ button or by pressing right arrow until the last character. Now add or append ‘rd.break’ after a space at the end of the line. And press ‘Ctrl+x’ to boot using the modified config.

Step-4: System will appear with command link viewing something like below.

switch_root:/#

Now you need to remount /sysroot file and give read/write permission.

switch_root:/# mount -o remount,rw /sysroot

Step-5:

switch_root:/# chroot /sysroot

‘chroot’ runs a command or an interactive shell from another directory, and treats that directory as root. It will take you to a new shell like below.

sh-4-2#

Step-6:

Here you need to give the ‘passwd’ command to give it a new password. it will prompt twice.

sh-4.2# passwd [press enter]

: ******* (123456)
: ******* (123456)

Step-7:

After all these steps the last step is to create a autorelabel executable file which the OS will take to relabel the configuration file. Next just exit from both shell and it will take some time(like 2min) to boot and you can enter with the new password.

sh-4.2# touch /.autorelabel
sh-4.2# exit

switch_root:/# exit

Wait for 2 minute and Login… Hurreeeh…!!! now access the root with your new password and you can change this with any password you want.