You are on page 1of 5

What-ever Articles Discussion About Us

Home › content
Topic
SSH: It's really not that scary Design (11)
by Megan McDermott, 29 October 2009 - 12:50am Graphics (2)
For a long time, I avoided using ssh. As a designer, I thought it would be too complicated and difficult to learn. CSS (14)
As it turns out, I was wrong! For the most part, ssh (and the shell commands needed to perform tasks) isn't that HTML (16)
difficult to do. Being able to use SSH will make it easier and faster for you to perform many common tasks on Drupal (6)
your web server. Even if you're on a shared hosting account, you may be able to access your website using SSH
Programming (5)
(check with your hosting provider to find out).
Server management (1)

What is SSH? Marketing (0)


SEO (3)
SSH, or Secure Shell, is a method of accessing servers securely on linux or other unix-based systems. Normally,
ssh is performed in a terminal using the bash shell (or command line). Using the command line tools available on
Difficulty
the server is where most of the convenience lies.
Beginner (20)
In Linux or Mac you can use ssh through the terminal. To use ssh on Windows you need to use a program called Intermediate (20)
PuTTY.
Advanced (16)
Many other utilities discussed in this article are actually part of the GNU coreutils collection. This collection is
commonly included with Linux, but also work on Windows, OS X and more. It possible to have a web server with Type
SSH, but not using GNU programs. If some of the commands below don't work on your server, contact your Reviews (0)
server administrator to find out which utilities your server is running. Opinion (1)
Tutorials (17)
Why use SSH?
Using ssh will allow you to perform more advanced tasks, faster. It does require you to learn some text
commands that may seem cryptic at first. The most common of these are easy to learn and remember.

Warning
Discussion topics
Always be careful when running shell commands. Make sure you understand what your command is doing
and double check to make sure your syntax is correct. If you are copying commands provided on a Webmaster's Corner
website or forum, it is important that you understand what the command is doing. Incorrect or malicious Web Design and Graphics
commands could erase your entire website or otherwise compromise your server.
HTML, CSS, and Javascript
More information on malicious commands. Web Programming and
Application Development
Web Database Development
Getting started: logging in Web Hosting and Domain
Using a terminal on Linux or Mac Names
Server Management
1. open a terminal
Promotion and Marketing
2. type ssh username@yourwebsite.com (probably the same hostname, username & password you use to
ftp) Search Engine Challenges
3. enter your password at the prompt Online Business and
eCommerce
Using PuTTY in Windows Website Critique Area

1. start up PuTTY Introductions


2. in the Host Name field, enter your host name (probably yoursite.com or whatever you use to FTP). Ensure Computer Help
that SSH is checked under Connection type. Click Open to start your session. Market Place
3. Say yes to the prompt asking you if you want to add this key to PuTTY's cache
TWF Feedback and
4. Enter your username and password at the prompt (probably the same hostname, username & password you Announcements
use to ftp)
Off-Topic Chat

Shortcuts
● use the u p a r r o w to cycle through recently used commands
● use m a n [ c o m m a n d ] to view the manual for that command (e.g. man ls). Press q to leave the manual.
● use c t r l + C to escape a command

Navigating around
Two commands are needed to view and navigate folder structures on your site. The ls (or li list) command shows
you the files and folders in a directory. cd (or c hange d irectory) command lets you move beteween folders. To
find out where you are, use pwd (short for p rint w orking d irectory). This will show you the current directory path.

Once you become familiar with your web server's structure, you will get very fast at navigating. This is often more
convenient than using a GUI-based FTP client or file manager that requires you to click to open directories.

When you first log in to your server you may be directed straight to your website folders or you may end up in a
folder for your user account. It might take some navigating around to figure out how to get toGenerated by www.PDFonFly.com
your website files. at 5/24/2010 5:21:23 AM
URL: http://www.apaddedcell.com/ssh-its-really-not-scary
Often going to /var/www or /www will get you where you need to be.

Sample commands
ls
list files in a directory
ls -l
long format list - shows permissions, file owners (individual and group), file sizes, and last modified dates
ls -a
shows all files (including hidden files, such as .htaccess)
ls -la
shows long format and all files at once
cd folder
navigate to the directory folder
cd folder1/folder2
navigate to the directory folder2 which is located inside folder1
cd ../
move up one level
cd ../../
move up two levels
cd ../../folder
go up two levels and navigate to the directory folder
cd /
go back to the site root
pwd
show current path

Shortcut
When enteirng a file path, press tab to auto-complete.

A sample ls command

A sample ls -l command

Generated by www.PDFonFly.com at 5/24/2010 5:21:23 AM


URL: http://www.apaddedcell.com/ssh-its-really-not-scary
Reading files
Several commands can be used to look at the contents of files:

file
prints the file type and some additional information about the file (varies depending on the file type)
cat
prints the contents of the file
more
prints the contents of the file on one screen (useful for longer files); press enter to scroll through the file and q
to return to the prompt.
less
an enhanced version of more with additional shortcuts. Use the up and down arrows to scroll.
head
prints the first 10 lines (by default) of the file
tail
prints the last 10 lines (by default) of the file

Sample commands
cat style.css
prints the entire contents of the file style.css
cat -n style.css
prints the contents of style.css with line numbers
head -20 style.css
prints the first 20 lines of style.css

Moving, copying, and deleting


Three more commands:

mv
move
cp
copy
rm
remove
These three commands are structured the same way and take the same options.

Common options
-r
recursive (includes all sub-files and folders)
-f
force (supresses any warnings or prompts) Generated by www.PDFonFly.com at 5/24/2010 5:21:23 AM
URL: http://www.apaddedcell.com/ssh-its-really-not-scary
-v
lists files as they are being processed

Shortcut
* is a wildcard. When used alone it represents all files in the directory. When included with other text it
represents any number of additional characters.

Sample commands
mv file.html ../
moves file.html up one level
mv file.html folder/file.html
moves file.html into folder
mv file.html file2.html
moves file.html to file2.html (effectively renames the file)
mv * folder/
moves all files in the current directory into folder
cp file1.html file2.html
copies file1.html to file2.html
cp * ../
copies folder contents up one level
cp -r * ../
copies folder contents up one level recursively (includes all sub-files and folders)
rm -rf *
removes all files and folders, including sub-folders, and suppress all prompts

Creating new directories & files


These are pretty basic commands:

touch
creates a new file, or updates timestamps on existing file
mkdir
creates a new directory

Sample commands
touch file.html
creates a new file called file.html
mkdir folder
creates a new folder called folder

Upgrading scripts using wget and unzip or tar


If you're running a CMS such as Wordpress or Drupal, you will probably need to upgrade the system and
modules or plugins quite frequently. Instead of downloading the upgrade to your hard drive, unzipping, and
uploading again, you can quickly complete the process directly on the server.

1. Navigate to the directory where your CMS or plugin/module resides. Depending on your hosting setup the
command will look something like this:
cd httpdocs/wp-content/plugins/ (for wordpress plugins)

cd httpdocs/sites/all/modules (for drupal modules)

2. Get the URL for the plugin or module you want to download (you should be able to right-click on the
download link and copy the link address).
3. Download the plugin to your server using the wget command:
wget http://example.com.com/theplugin.zip

If you're ugrading more than one plugin or module at once, you can separate them with spaces, like this

wget http://example.com/theplugin1.zip http://example.com/theplugin2.zip

4. Wait for the plugin to download to your server


5. Extract the file using unzip or tar (depending on the file type):
unzip theplugin.zip

tar -xvzf theplugin.tar.gz

Depending on where the files extract to, you may need to move them around to overwrite the existing versions.
Generated by www.PDFonFly.com at 5/24/2010 5:21:23 AM
URL: http://www.apaddedcell.com/ssh-its-really-not-scary
Discussion
To discuss, ask questions or comment on this article please see the Webmaster Forums discussion on SSH: It's
really not that scary.

What's next?
Stay tuned for the next article in this series on managing file permissions using CHMOD. Further articles will cover
more advanced command line utilities.

Resources
● List of Unix utilities
● Guide to Linux File Command
● Malicious commands (information and examples)

About the Author


Megan is co-founder and editor of A Padded Cell and lead administrator at The Webmaster
Forums. She has been designing websites since 1997 and currently works at the University
of Waterloo. In her spare time she likes practicing yoga and being nice to the environment.
Read her web design blog at MeganMcDermott.com.

View full user profile

Contact us Contribute Advertise Hire us Login

aPaddedCell © Copyright 2006-2007 InterMedia. Site and all articles (unless otherwise specified) licensed under a Creative Commons License.

Generated by www.PDFonFly.com at 5/24/2010 5:21:23 AM


URL: http://www.apaddedcell.com/ssh-its-really-not-scary

You might also like