|
||||||||||||||||||||||||||||||||||||
|
Although I've been using SSH for quite some time, I still consider myself very much a beginner. It's something I don't use often, but some basic SSH and Unix command knowledge has been a very handy thing to have. The following guide and simple exercises are a non-geeky introduction to the wonderful world of SSH and Unix commands. What is SSH?Developed in 1995, SSH (Secure Shell) was developed as a secure alternative to Telnet. What can you use SSH for?SSH, depending on the level of access your host allows, lets you perform all sorts of diagnostics and file management functions, including archiving/decompressing files; setting passwords for particular folders, backing up MySQL databases and managing CRON jobs in a secure environment. It's a manually intensive way of going about things, but very powerful and flexible. Accessing SSHYou'll need to ask your web host if you have access to SSH. Some hosting companies are really, really paranoid about letting their clients have SSH access, claiming security concerns. It's my understand that if this is their concern, then they don't really know *how* to secure their servers while still allowing for SSH access. SSH softwareYou'll need a Telnet client which has support for SSH. A lightweight, freeware application that I use is PuTTY. Using PuTTYAfter firing up the application, ensure the port setting is 22, which is the secure option. Fun with SSH and Unix commandsYou're now looking at the command line for the server operating system. Of course, there's only a specific set of Unix type commands you'll be able to access, well at least I hope there is :). This will vary from host to host. Unix commands can be also be used on other *nix type systems such as Linux and FreeBSD. You may notice a little bit of a lag from when you type something to when it appears on the screen. This is normal and depends on a number of factors including activity on the server and your ISP connection Let's start getting a little familiar with some simple exercises, commands and tasks to get you acquainted which should work in most host's environments.
Now we'll take a look at the calendar for the current month. Type:
Let's try the calculator. Type:
hit enter, then type:
hit enter.
See how easy command line stuff is ;). Ok, let's go on... Basic navigationType: ls This command lists folders and files, in the directory your logged into. To change to another folder, type:
Type ls again to see the contents of that folder, or you can continue drilling down by using cd (folder name) commands
To return to your home directory, i.e. the top level, type:
Those couple of commands should take care of things in relation to basic navigation. Determining space usageTo check how much space each folder is using in your account; type the following command:
For just a summary of the total space used
Viewing the contents of filesTo take a peek at the contents of a file, use this command:
This will display the contents of the file one screen at a time. You advance through the screens by hitting the spacebar. At the end of the file, you'll be returned to the command prompt. Creating and editing filesFor this exercise, we'll first create a blank file and then edit it. return to your home directory (cd ~) and type the following command
"touch" is the command which creates the file Now we'll put some content into the file using "pico", a very basic text editor. Type:
Believe it or not, the screen you see next is very much like the cutting edge word processors from the late 80's :). Type in a few random lines. You'll see at the bottom of the screen a menu with functions containing keyboard commands for those functions. The "^" characters you see indicates that the Ctrl key on your keyboard needs to be used in conjunction with another key. To save the file we've just edited, use Ctrl+ X
Creating a directory/folderNice and simple; navigate to the top level folder where you want to make the new subfolder and type this command:
Moving/copying filesUsing the test.txt we created, to make copy of this file in another folder
where foldername is the name of the directory you wish to copy the folder into.
If you don't wish for a copy to be made, but just for it to be moved, use this command instead:
Deleting files and foldersTo delete a file, in this case the one we just created, change to the folder that it's in and type:
Warning: Depending on your host's setup, you may *not* be asked to confirm deletion when using an rm command; therefore always use this command with care. To remove an entire folder and the sub-folders beneath it:
where folder is the directory name Finding files and folders File base structures can get pretty complex and it's easy to lose track of where things are. This simple command will help you find what you are looking for
You don't need to know the tail extension for the file, but the more information you can provide, the more accurate the search will be. Connecting to a MySQL databaseJust a simple exercise for this one. At the command prompt, type
where username is the username associated with your MySQL database and dbname is the database name. You'll then be prompted for your password. This prompt should then appear, indicating you are now connected to the database:
To view the tables within your database, type:
To get back to the normal command prompt, type:
Archiving files and MySQL databasesIf you've ever tried ftp'ing a few hundred megabytes of site files or a large database to your machine, you'll know just how time consuming this can be. Archiving files and folders is a relatively simple task via the command line. Learn more about doing so in my article on backing up data. Getting helpYou can get help on any particular command during your ssh session using the following syntax: man command .. where command is the name of the function you want to discover more about; e.g.
To scroll down through the help file, hit your enter button To quit from the help system, type q Finishing your SSH sessionTo exit your SSH session either just close the window or type: exit Handy tipTyping out the same commands, especially complex ones, can get a little time consuming. You can use the up arrow on your keyboard to scroll through previously issued commands. The "history" command will also display a list of your previous commands.
There's hundreds of other more powerful commands and functions that you can use in the SSH environment and also faster ways of achieving some of the above, but this tutorial was just to whet your appetite and build up some confidence :).
I hope you found it useful. For help with using MySQL via the command line; see MySQL.com Michael Bloch Copyright information.... This article is not available for reproduction without explicit written permission from Michael Bloch and Taming the Beast.net
Click here to view article index
|
|
||||||||||||||||||||||||||||||||||
|
Search Taming the Beast.net |
|
our office is powered by: |
| Learn more about our social and environmental commitment | |
|
Get
paid cash taking online surveys - free to join online |
In Loving Memory - Mignon Ann Bloch
copyright (c) 1999-2007 Taming the Beast Adelaide - South Australia
|
|