SSH & SCP
How can we connect with other devices and share files from one to another device while connected with the same router?
SSH
Secure Shell, sometimes referred to as Secure Socket Shell, is a protocol that allows you to connect securely to a remote computer or a server by using a text-based interface.
Install open-ssh server in your localsudo apt-get install openssh-server ii
Note: you need to install the open-ssh server in both devices which you want to connect
How to connect a device to another device using ssh with IP address, username, and password of the other device?
$ ssh username@ip_addressExample: ssh navgurukul@192.168.3.105
After running this command, if the username and IP address get matched then it will ask for the password, you have to enter the correct password of another device’s username.
once the username and password match then you will log in (connect) to that device console
Connect your virtual device to your local terminal using .pem file
$ ssh -i file.pem username@ip_addressExample: ssh -i jagan.pem ubuntu@192.168.3.105 // use sudo if required
Now you can access another device console :)
SCP
Secure copy protocol (SCP) is a means of securely transferring computer files between a local host and a remote host or between two remote hosts.
How to transfer files from one device to another device using the IP address, username, and password when they are connected with the same router?
To transfer file from your device to another device using SCP,
follow the below command:
$ scp your_filename username@IP_address:/directory/eg. scp image.jpeg navgurukul@192.168.3.105:/home/navgurukul/Desktop$ scp -i <pemfile_path> -r <directory_path> <username>@<ip_address>:<server_path>eg. scp -i keychain.pem -r /home/jagan/app/build ubuntu@192.168.3.105:/var/www/html/react-app-i : for login with pem/ppk file
-r : for transfering a whole directory
Here your_filename
= you have to select the file location that you want to share.
username
= username of that device to which you want to share your file.
IP_address
= IP address of that laptop.
directory
= here you have to select the root directory of the secondary device where you have to share the file.
for checking the directory use command pwd
After this command and if the username and IP address match and also if you have assigned the correct directory name then it will ask for the password for the username and if you enter the correct password then it will start uploading files to the secondary device. :)
To transfer file from secondary device to your (primary) device using SCP,
follow the below command:
$ scp <username>@<IP_address>:/<secondary_file_location> <your_location>eg. scp ubuntu@IP_address:/home/jagan/file.txt /home/app
here .
is the default present location
simple HTTP server ( npm )
You can also share your files from your device ( computer ) while connected with same network (router)
You simply need to install simplehttpserver
which is available in npm packages. run the below command to install simplehttpserver
$ sudo npm install simplehttpserver -g
after installing open your console and type the command
simplehttpserver
to open the server ( your server will run on the default port 8000
)
visit localhost:8000
or your_IP_address:8000
to get access to your files (read and download)
you can change the port by using -p port
$ simplehttpserver -p port
Ex- $ simplehttpserver -p 8080
to run on port 8080
Happy coding :)