Putty Commands For Basic SSH

0 Comments Posted In: Web Post

When getting more experience in web development. It's a good idea to know how to connect via Secure Shell (SSH). If you have upgraded to a VPS server or a dedicated server you will have access to this.

When searching for SSH connecting you will hear people talking about "Putty". Putty software allows you to remote login to computers systems.

When you SSH into a web server you are using a cryptographic network protocol. This allows you to make a secure connection over an unsecured network. there are some configurations and other techniques that can help accomplish certain tasks.

Connecting With Secure Shell

Putty Commands

You really won't need a lot of information about SSH to be a great web developer. It is a good idea to know the basic navigation and file management. When connecting to your server, you will need to know the IP address, username, and password.

Putty Connect

  1. Type IP Address in Host Name and click Open.
  2. Enter username.
  3. Enter password.

Putty Connect

Once connected it will be nothing but a black background and white text. Something like your command prompt, or DOS in Windows. There is no use for your mouse, everything is done by commands on the keyboard.

SSH Basic Commands

When you first connect via SSH, be careful. Any changes to config files or settings can change how your server is running.

When you want to run a command you must hit "Enter". Your first Putty command, type:

top

Putty Top

This will show you server hardware information and what processes are currently running. This can be handy if you are experiencing lagging or slow response times. You can see what process are taking RAM or CPU.

It is a good idea to know what should be running even if nothing is wrong. This way you can easily identify if there is a problem.

Create A Directory and File

My commands are just examples. You may have to be altered to match your server's hierarchy.

You can easily create and edit directories and files. Navigate to your root web directory on your server by using the change directory command.

cd /var/www/vhosts/httpd/

Let's make a new directory called "scripts". Type the following command:

mkdir scripts

Now that you have a "scripts" directory it time to make an index file. To make a new file let's us the vi editor. Type the following command:

vi scripts/index.php

You will now have a new window with nothing but black. This is the server's text editor, like notepad on a computer. Hit the "i" key on your keyboard. This will trigger a "-- INSERT --" at the bottom of the screen.

We are now ready to type in the editor. Type the following PHP script:

<?php
echo "New SSH Page";
?>

Once we are done typing we have to let the editor know. Hit the "ESC" key on the keyboard. Now save the file by using:

:w

This write the changes to the file, and now to exit the editor type:

:q

Congratulations you have created your first file by using SSH. If you navigate to your root website with your internet browser. You should see it display "New SSH Page".

Create SSH Page

Manage MySQL Database

Another good technique to learn is how to manage your MySQL databases. There will be a time when your MySQL tables may go down, get corrupted, and needs to be repaired.

You can repair MySQL tables with phpMyAdmin. But there have been better success rates when repairing them through SSH.

The reason is when repairing it through a client side GUI. Visitors can still try to access your table while you are trying to repair it. In an SSH environment, you can deny visitors while you repair.

MySQL Commands

To login into your MySQL database use the following commands:

mysql -u username -ppassword

You need to put the -u space username space -p then password. If entered correctly it will bring into the MySQL status. Now choose your database using:

use database;

This should get you in where you can use your standard MySQL queries. Like show tables, select, insert, and repair.

Remember to end everything with a ";".

Putty Command Cheat Sheet

Here are some of the most common commands you can use in your SSH environment.

Show server status

top

create directory

mkdir new-folder

Move To Another Directory

cd /folder/folder/folder/

Move up a directory level

cd ..

Show the current path

pwd

List all files in a directory

ls -al

List all files with a specific extension

ls *.php

Copy a file

cp old-file.php backup/new-file.php

Move a file

mv old-file.php backup/old-file.php

Create a file

touch new-file.php

Edit file with VI editor

vi new-file.php

Search for a file

find . -name new-file.php -print

Delete a file

rm old-file.php

Delete directory

rmdir backup

Change permissions

chmod 775 backup

exit SSH client

exit

Putty Basics

These are some of the basic commands you can do in an SSH manager. Using putty is one of the most common ways. Putty is an open source application and you can download for free.

Just be careful if you don't know what you are doing. Start with the basic commands. Once you are comfortable in the environment start learning more advanced techniques.

Advertisement

Rating: 
Average: 5 (1 vote)

Copyright © 2017 www.webhostdesignpost.com