How to use Putty: commands and useful features

PuTTY is an open source SSH client. The Secure Shell (SSH) protocol is used to securely connect to remote servers. In fact, PuTTY is a terminal for connecting to a server and then managing it. In addition to SSH, PuTTY supports a number of other network protocols: SCP, Telnet, rlogin, and raw socket. PuTTY was originally developed for Microsoft Windows, but was subsequently ported to various operating systems. To work effectively with the terminal, you should know a number of PuTTY commands.

Getting started with PuTTY

PuTTY is fairly easy to use, unlike other clients that require a long installation. Work with PuTTY begins with downloading the installation file to a local computer running Windows. It is recommended that you download the latest version of putty.exe from the official site. After saving, run putty.exe and click Next. In the next step, select the Create a desktop icon for Putty check box and select Next again . After that, click Install to complete the installation process.

Launch PuTTY by clicking on the desktop icon. At startup, the configuration page will open. The following details must be indicated on it:

  1. In the Host Name or IP address field, enter the IP address of the server you want to connect to or its domain name in the format server.yourdomain.com (the top-level domain can be any).
  2. In the Port field, specify 22. This is the standard port for the SSH protocol.
  3. As the connection type , select SSH.
putty commands

After that, you must click Open. A security warning window will appear, indicating that you trust the server you are going to connect to. This situation is normal when you connect to the new server for the first time, just click Yes.

A terminal window will appear in which you will be asked to enter a username and password to access the server. Enter your username and press Enter. As you type your password, you may notice that characters are not displayed in the terminal window. This should not confuse you, as it is done for security reasons. Enter the password and press Enter again . If everything is done correctly, the terminal should signal a successful login. Now in the terminal window you can enter commands to the Linux server, download and upload files to the server.

Sometimes it happens that no commands are entered in the PuTTY window. The reason for this, most likely, is incorrectly entered data for connecting to the server - IP address, port, type of connection, or login and password. In this case, you cannot type anything in the terminal window. It is necessary to restart the program and once again check the entered data.

30 useful SSH commands in PuTTY

The main field of application of PuTTY, as already mentioned, is the management of Linux servers from computers based on Windows. Below we have compiled a list of commands for PuTTY that are regularly used in server management.

The first group of commands allows you to navigate the server.

ssh putty commands

1. How to find out which directory on the server you are currently located in:

pwd

The pwd command shows the path to the current directory.

2. Go to the specified directory:

cd

The cd command is used to navigate to a given directory on the server.

Example: cd / home (moves you to the / home directory).

3. Remain in the current directory:

cd.

Using this command, you signal to the server that you want to remain in the same directory in which you are currently located. Typically, this command is used in combination with others to indicate that they should be executed in the current directory.

4. Move one level up:

cd ..

The above command allows you to go up one level relative to the current directory.

5. Return to the previous directory:

cd -

The specified command returns you to the directory from which you moved to the current one.

6. Go to the home directory:

cd ~

The command allows you to move to the / home directory (the main working folder of the Linux user).

7. Go to the root directory:

cd /

The above command goes to the root of the hard drive.

View folder contents

The following are PuTTY commands that allow you to remotely view the contents of directories on a server.

putty no commands are entered

8. Show all files and folders in the current directory:

ls

Using the ls command in a folder displays all its contents.

Example: ls / home (displays the entire contents of the user's home directory).

9. Display all files and folders in the directory, including hidden ones:

ls –a

10. Show all files and folders with an indication of their size:

ls –h

11. Recursively display all subdirectories of the current directory:

ls –r

12. Display folder contents sorted by size:

ls -is

13. Display all folders in the directory with detailed properties:

ls -alh

Copy files and folders

This section provides a list of PuTTY commands that allow you to copy files and folders.

putty command list

14. Copy file:

cp

To create a copy of the file, use the cp command. The command syntax is: cp [file] [path to copy].

Example: cp filename.php /home/filename.php

15. Copy the folder with all the files in it:

cp –r

This command recursively copies the folder with all attached content.

16. Copy and rename the file:

cp filename.php /home/filename2.php

Moving files and folders

In Putty, the commands below allow you to transfer files from folder to folder.

17. Move file:

mv

The mv command is used to move files. Command syntax: mv [file] [path to move].

Example: mv page.php /home/page.php.

18. Move and rename the file:

mv page.php /home/newpage.php

19. Move the file to a directory one level up:

mv [file name] ..

Example: mv index.html / ..

Creating Files and Folders Using PuTTY Commands

The following group of commands is used to create new files and directories on the server.

20. Create folder:

mkdir

Example: mkdir new-folder

21. Create file:

touch

The touch command allows you to create empty text files with various extensions.

Example: touch index.php

Creating and unpacking archives

putty run commands

Useful when working with PuTTY and the command to start archiving / unarchiving files.

22. Compress the folder into a ZIP archive:

zip -r [folder_name.zip] [folder_name]

Example: zip -r newfolder.zip newfolder

23. Unzip the ZIP archive:

unzip

Example: unzip newfolder.zip

24. Compress the folder to the TAR archive:

tar -czvf [folder_name.tar.gz] [folder_name]

Example: tar -czvf wp-content.tar.gz wp-content

25. Unzip the TAR archive:

tar -xvf

Example: tar -xvf wp-content.tar.gz

Delete files and folders

26. Delete file:

rm

To delete a file on the server, use the rm command .

Example: rm index.php

27. Delete all files in the directory:

rm *

This command clears the specified directory from the files contained in it.

Example: rm * / home / folder

28. Delete folder:

rmdir

Example: rmdir / home / folder

Change file / folder permissions

putty commands

Finally, the chmod command is special in PuTTY , which is responsible for access rights to files and folders. It allows you to set the rights to read, write and execute a file or folder.

The syntax of the command is as follows:

chmod [options] [rights] [file_name]

For instance:

29. Change folder permissions:

chmod 754 newfolder

30. Change access rights to the folder and all files in it:

chmod -R 754 newfolder

We'll figure out what the numbers in the command syntax mean.

There are three groups that may have file and folder permissions on Linux:

  • file owner
  • file owner group;
  • other.

Moreover, they may have the following rights to work with the file, indicated by numbers:

  • right to read (4);
  • right to record (2);
  • right to exercise (1);
  • no access (0).

Three digits, for example, 754, sequentially set access rights for the file owner (first digit), group (second digit) and all the others (third digit). Each of the numbers is the sum of the rights to read, write and execute.

So, in the given example, the number 7 gives the owner of the file the right to read, write, and execute ( 4 + 2 + 1 = 7). The number 5 gives the group the right to read and execute ( 4 + 1 = 5), and the number 4 gives everyone else the right to read only (4).

Using a similar formula, you can create any combination of rights depending on your needs.

Conclusion

In conclusion, here is a list of some useful features that will help simplify your work with PuTTY:

  • You can paste the command copied from a third-party source into the PuTTY terminal window by pressing Shift + Insert.
  • You can quickly delete a printed command by pressing Ctrl + U.
  • You can interrupt the execution of the currently running command by pressing Ctrl + C.
  • Clear the terminal window from the results of the previous commands - Ctrl + L.

This material is a brief overview of working with the PuTTY terminal client. For more information on PuTTY commands, use the Unix / Linux command reference.

Source: https://habr.com/ru/post/K9660/


All Articles