OpenSSH Configuration and Usage Part 2
Hi guys in our previous tutorial we have learnt and practiced few ssh commands (different switches).Today we will continue with ssh utility and transfer files with secure environment. In this tutorial we will learn commands with options like ssh with wall option, scp –P, scp –r and scp –C, scp –c.
Broadcasting a Message to a System
The following example sends a message on the remote system. Syntax ssh username@hostname/IP wall “type your message here”.
Message sent from server
[Server@faraz ~]$ ssh [email protected] wall "Hi, It is informed you that i am using wall Msg" [email protected]'s password: [Server@faraz ~]$
Message received in client machine
Broadcast message from [email protected] (Wed Feb 3 13:31:47 2016): Hi, It is informed you that i am using wall Msg
Secure Copy SCP
SCP means of securely transferring files using the secure shell (SSH) protocol between a local computer and a remote host and between two remote hosts. This utility uses same authentication mechanism as SSH.
To run a secure shell on or securely copy a file to/from a remote system you need to sure that you have following criteria. The remote system must be running sshd daemon such as OpenSSH, you must have an account on the remote system and the server must positively identify the client.
SCP for Local System to Remote System
Copy files from local system to remote system by using command SCP. Syntax is scp path_of _source_file user@to-host:path_of_destination_file (where you want to paste that file)
[Server@faraz ~]$ scp /home/Server/filetransfer.txt [email protected]:/home/Client/ [email protected]'s password: filetransfer.txt 100% 1631 1.6KB/s 00:00 [Server@faraz ~]$ ssh [email protected] [email protected]'s password: Last login: Wed Feb 3 13:01:00 2016 from 192.168.56.101 [Client@faraz ~]$ ls Desktop Documents Downloads filetransfer.txt Music Pictures Public ssh.config Templates testfile.txt Videos [CLient@faraz ~]$
SCP for Remote System to Local System
Copy files from remote system to local system by using SCP command. Syntax is scp user@from-host:path_of_source_file path_of _destination_file
[Server@faraz ~]$ scp [email protected]:/home/Client/testfile.txt /home/Server/ [email protected]'s password: testfile.txt 100% 79 0.1KB/s 00:00 [Server@faraz ~]$ ls 1234 Desktop Documents Downloads historysave.txt Music newstring.file Pictures Public Templates testfile.txt Videos [Server@faraz ~]$
SCP for Remote System to Remote System
This command is very useful when you are going to copy file remote system to another remote system on a network. Copy files from remote to remote system by using SCP command. Syntax is scp user@from-host: path_of_source_file user@to-host:path_of_destination_file
[Server@faraz ~]$ scp [email protected]:/home/abc/123abc.txt [email protected]:/home/Client/ [email protected]'s password: [email protected]'s password: 123abc.txt 100% 76 0.1KB/s 00:00 Connection to 192.168.56.104 closed. [Server@faraz ~]$
SCP with some Useful options
-P (in Caps) option is used to connect to the port number if you changed the default port
Syntax : scp –P port_no source_file user@to-host:path_of_destination_file
[Client@faraz ~]$ scp -P 122 historysave.txt [email protected]:/home/ [email protected]'s password: historysave.txt 100% 29MB 3.1MB/s 00:09 [Client@faraz ~]$
-r option is used to recursively (procedure to successive results) copy directory with all its contents(files/subdirectories)
Syntax scp –r file/dir user@to-host:path_of_destination
[Server@faraz ~]$ scp -r Documents [email protected]:/home/Client/Desktop [email protected]'s password: testfile.txt 100% 79 0.1KB/s 00:00 string.file 100% 76 0.1KB/s 00:00 [Server@faraz ~]$ ssh [email protected] ls /home/Client/Desktop [email protected]'s password: Documents known_hosts [Server@faraz ~]$
-C (in caps) is used to compress the file to make transfer faster than normal transfer.
Syntax scp –C file-name user@to-host:path_of_destination.
First command transferred file in 9 seconds .Second one transfered file (compressed) in 2 seconds
[Server@faraz ~]$ scp historysave.txt [email protected]:/home/Client/ [email protected]'s password: historysave.txt 100% 29MB 3.1MB/s 00:09 [Server@faraz ~]$ scp -C historysave.txt [email protected]:/home/Client/ [email protected]'s password: historysave.txt 100% 29MB 20.9MB/s 00:02 [Server@faraz ~]$
-c is used for encrypt the session of file to transfer on other system. Syntax scp –c ciper file-name user@to-host:path_of_destination
[Server@faraz ~]$ scp -c 3des newstring.file [email protected]:/home/Client/ [email protected]'s password: newstring.file 100% 76 0.1KB/s 00:00 [Server@faraz ~]$
In this tutorial we learnt scp command with useful options –P, -r, -C and –c. I hope you enjoyed part2 .We will discuss more commands in our next tutorial part3
Thanks