Tuesday, April 6, 2021

HOW TO ZIP (COMPRESS) AND UNZIP (EXTRACT) FILES

 Compressing several files and folders into a single distributable file is the most common way done by many computer users around the world. In Windows, you can simply use Winzip, WinRAR, 7Zip, and so on to zipping and unzipping file. If you’ve installed full Linux distros with GUI, you can also find and use similar app to do similar tasks. But what about a Linux server which you can only access it via SSH client? Realizing that many files are zipped and distributed as .zip file, also that you may need to zip several files into one .zip file so you can download it or transfer it elsewhere, so here it is I tell you how to do zipping and unzipping in a Linux-based VPS or Dedicated server via SSH client (in this case I use Putty, in Linux or Mac you can use Terminal).

Purpose:
I will show you how to zip / compress file and to unzip / decompress / extract file in Linux server via SSH

HOW TO UNZIP / EXTRACT FILE?

Step 1.
Open Putty or Terminal then login to your server via SSH

read: How to use Putty to SSH

Step 2.
Once you are logged into your server via SSH, now navigate to the directory where the .zip file you wish to unzip is located there.

read: How to navigate from one directory to another in SSH


Step 3.
Then type following command to try unzipping

1
unzip [filename].zip

example

1
unzip screenshot.zip

you may be successful but you may not.

error message:
– bash: unzip: command not found

In this case you have to install it first.

Step 4.
Use following command:

for Debian and Ubuntu:

1
apt-get install unzip

for Red Hat Linux/Fedora/CentOS users:

1
yum install unzip

Step 5.
That’s it. Now you can try unzipping it again using command in step 3 above.


HOW TO ZIP / COMPRESS FILE?

Step 1.
Open Putty or Terminal then login to your server via SSH

Step 2.
Once you are logged into your server via SSH, now navigate to the directory where the files and folders you wish to zip / compress are located there.

Step 3.
Use following command:

1
zip [zip file name] [file 1] [file 2] [file 3] [file and so on]

example:

1
zip example.zip 1.txt 2.txt 3.txt

In this example we’ll compress files 1.txt, 2.txt and 3.txt into a single example.zip file


you may be successful but you may not.

error message:
– bash: zip: command not found

In this case you have to install it first.

Step 4.
Use following command to install zip function:

for Debian and Ubuntu:

1
apt-get install zip

for Red Hat Linux/Fedora/CentOS users:

1
yum install zip


Step 5.
That’s it. Now you can try zipping it again using command in step 3 above.


Link: http://www.servermom.org/how-to-zip-compress-and-unzip-extract-files/65/

USING PUTTY TO SSH TO YOUR SERVER FROM WINDOWS

I think it is really important to show you how to use Putty tool to access your server via SSH connection. This is a very basic skill every server admin should know. Since this blog is aimed to helping babies (newbies with no knowledge about Linux and server at all), so I’ll write this simple tutorial as a basic guide every newbie should know. It means you can skip this post if you knew it already.

But first, it is better to know what the Putty is. Being a well-known and most used tool, Putty is basically a client for the SSH, Telnet, rlogin, and raw TCP computing protocols and as a serial console client. Its simplicity makes this tool widely used. The program is originally written for Windows-based computers but then it has been ported to various other operating systems, even on mobile devices running Symbian. The tool is compatible for Windows XP, Vista, 7 and even Windows 8.

Download Putty
You can download Putty here or via direct link here.

Now you have Putty on your computer. Assuming you have a server you wish to manage via SSH port, so here it is the way I use Putty which you can follow..

Step 1.
Download Putty.exe

Step 2.
Double-click it to launch the main interface. It should look like this..


Step 3.
Now enter the Host name of your server obtained from your provider. It can also be the IP address.

Step 4.
Leave the port field as it is (port 22 – default) unless your provider changed it to another port but they should tell you.

Step 5.
Make sure the “SSH” option is checked.


Step 6.
That’s it then click the “Open” button

Step 7.
Now you’ll see another window open. If it is your first time using Putty to SSH-ing your server, you may notice an alert like this one. Simply hit Yes button.


Step 8.
Putty will bring you to login to your server via SSH connection. In this case you may enter your root password.


Congratulation you are now getting access to your server via SSH. You can try some basic command. In this case I’ll try to see RAM usage in my playground server:

Command to use:

1
free -m

It will return like this..


Quick tip:

In Putty, you can use mouse right-click to paste any text. 

Link: http://www.servermom.org/using-putty-to-ssh-to-your-server-from-windows/46/

Monday, April 5, 2021

Copy files from/to remote server using PuTTY pscp

Once you install and setup PuTTY application you need to login to your server with hostname and port number details. 

Install PSCP as well and login to PuTTY terminal.


1.Download PSCP.EXE from Putty download (https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html) page

2.set New Path in environment variable  = C:\Program Files\PuTTY\pscp.exe

3.now open command prompt type pscp if pscp is successfully installed it will show its version.


Okey pscp now successfully setup.



Transferring file from server to localhost

Now we have to zip the directory which we want to copy because without zip we cant copy directory.


1. First zip a directory using putty 

   Goto the directory folder the make a zip file of that directory by following command = zip -r directoryName *

   From test server: zip -r ready_products * 

   It will make zip file of ready_products

   

   if you need unzip that folder enter unzip latest.zip

   

   if you need to delete the zip folder the enter unlink folder.zip or rm folder.zip

   

2.use the following command to copy file form remote server to the local system

So to copy the file /etc/hosts from the server example.com as user fred to the file c:\temp\example-hosts.txt, you would type

e.g: pscp -P 22 fred@example.com:/etc/hosts c:\temp\example-hosts.txt

   

    From test server : pscp -P 22 kldev@example.com:/var/www/project/storage/app/public/images/ready_products.zip C:\wamp64\www


Now Transferring file from localhost to remote server


1. pscp -P 22 filename_from_localhost kldev@server_ip_address:/server_folder_location


e.g.1 pscp -P 22 Library_Management.zip kldev@93.100.111.222:/var/www/Library_Management_Project/public_html/


e.g.2 pscp -P 22 ready_products.zip kldev@example.com:/var/www/project/storage/app/public/images/


Link 1 : https://stackoverflow.com/questions/6217055/how-can-i-copy-a-file-from-a-remote-server-to-using-putty-in-windows

Link 2: https://akshay-waingankar95.medium.com/copy-files-from-to-remote-server-using-putty-pscp-7567a0631c9d

Link3: https://www.ssh.com/ssh/putty/putty-manuals/0.68/Chapter5.html