SSH/Telnet Linux Command Line Tutorial

Joined: 11/28/2008

I was just doing some stuff on the command line and I had to go dig up this post I did at another forum a long time back. THen I though I ought to add it here.

Telnet vs. SSH

Telnet is an insecure way of accessing the server command line and is therefore not an option. SSH (Secure Shell) is a secure replacement for Telnet which gives the same type of access.

Accessing SSH

SSH can be accessed by an applet included in certain cPanel themes. It is preferable to access through an SSH program installed on your own computer.

For Windows, Putty is recommended ( http://www.chiark.greenend.org.uk/~sgtatha...y/download.html).

Windows users can also try WinSCP (http://winscp.vse.cz/eng/), a GUI that can handle some commands.

Mac OSX users can open a terminal window and enter ssh -l username yourdomain.com

For Mac 7.5.1 or higher you can use MacSSH (http://www.macssh.com

Useful SSH commands

When using SSH you are accessing the server's command line (Similar to MSDOS).
Here is a short list of commonly used commands:
(tip: when using Putty you can use the "right click" to copy and paste commands and information)

man
Display command manual (use: man [command])

logout
Logout of SSH

exit
Logout of SSH

Ctrl + C
End current command

dir
Directory listing

ls
Better directory listing with more options (type "man ls" for more information. Note: The "l" is an "L"

tar -cpzf filename.tar.gz
Tar (compress a number of files into one file) the current directory
Replace "filename" with an appropriate name.

tar -xzf filename.tar.gz
Untar (uncompress a number of files out of one file) a file
Replace "filename" with the file's name.

lynx
Lynx is a text based browser installed on the server that can be accessed via the command line or by cron.

cd /home/username
Navigate into a directory on the server (~ Navigate to your home directory, you can use "~" as part of the path: cd ~/public_html.
Replace "/home/username" with the appropriate directory.

whereis [function]
The easiest way to find the actual path to perl, sendmail, etc
Replace "[function]" with the function name e.g. "sendmail".

rm
Remove/delete (use rm -r to delete recursive directories. Type "rm --help" for full help, there is no way to undelete)

top
List running processes and check server load (type h for help and q to exit the "top" display.

mysql -u[Username] -p[Password] [Database Name] < filename.sql
Dump a SQL file into a MySQL database. Note the "<".
Replace "[Username]" with the database username (generally controlpaneluser_databaseuser). Replace "[Password]" with the database password and replace "[Database Name]" with the database name. Finally change "filename.sql" to the correct filename/location.

mysql -u[Username] -p[Password] [Database Name] > filename.sql
Dump a MySQL database to a SQL file. Note the ">".
Replace "[Username]" with the database username (generally controlpaneluser_databaseuser). Replace "[Password]" with the database password and replace "[Database Name]" with the database name. Finally change "filename.sql" to the correct filename/location.

mkdir directory_name
Make directory
Replace "directory_name" with the directory you want to create' name.

ln -s real/path [link name]
Create a symlink to a path
Replace "real/path" with the physical (real) path to the file. For example /home/user/downloads. Also replace "[link name]" with what you would like the symlink to be called. To remove the sym link use "rm [link name]".

pico [filename]
Easy to use text editor to edit files
Replace "(filename)" with the filename to open e.g. "pico file.txt"

wget http://www.example.com
Wget can grab files from a web site or even the entire website in its directory structure and copy them to your server. Type man wget to see all of your options.

Resources for learning about accessing the command line via SSH

http://web.reed.edu/cis/help/unix.html (Essential Commands)
http://www.ctssn.com/
http://linuxcommand.org/learning_the_shell.php
http://helpdesk.ucf.edu/secure/putty.html
http://oregonstate.edu/cws/tutorials/command-shell/ (Has some basic commands at the bottom)
http://www.indiana.edu/~uitspubs/b017/
http://www.ict.ic.ac.uk/resources/document...ix/howto/u1.htm
http://www.stat.ohio-state.edu/current/support/ssh/unix.html
http://www.talisman.org/unix/commands.html

If you liked this post, you'll love The Open Source Ministry Forum
And, the Open Source Ministry Blog {

Joined: 11/28/2008
very useful bob. thanks.i've

very useful bob. thanks.
i've never needed to use SSH, but i know it can be helpful to know a few back tricks when phpmyadmin isn't available.

Joined: 11/28/2008
I typically use it for wget

I typically use it for wget or Lynx, tar, rm, top, and before cpanel improved the cron interface by adding all the proper feature I would use ssh for crontab and pico (for editing the crontab file).

I don't know what I would do without ssh sometimes.

If you liked this post, you'll love The Open Source Ministry Forum
And, the Open Source Ministry Blog {

Joined: 11/28/2008
I don't know what I
QUOTE
I don't know what I would do without ssh sometimes.

hop on one foot? may as well get some good PR in the meantime if you don't have SSH.
also, that's quite the list of resources.
good work /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />

Joined: 11/28/2008
What about vi? it's a great

What about vi? it's a great text editor!

And my favourite Shell client is Tera Term Pro (with the SSH extension), though it is getting a bit old I suspect, and is not compatible with SSH2 (or whatever the newer version is). It has copy and paste (which PuTTY seems to lack) and allows for a horizontal scrollbar (ie very wide screen, so no wrapping/trucation - great for MySQL db queries!

Tera Term Pro:
http://hp.vector.co.jp/authors/VA002416/teraterm.html
SSH extension:
http://www.zip.com.au/~roca/ttssh.html
You can create shortcuts with commandline parameters that connect you straight up to your chosen server (prompting for username/password)

Though, I like the Terminal on the Mac - if it allowd for a horizontal scrollbar, it would be king. But it does have transparency so you can stack the terminal window on something else and read what's behind.

Another way of connecting using SSH on the command line is:
ssh user@domain

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified

Joined: 11/28/2008
Wow, just found a new version

Wow, just found a new version of Tera Term Pro - still free but obviously been taken on by someone else now, and is compaitble with SSH2

http://www.ayera.com/teraterm/

/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" />

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified

Joined: 11/28/2008
I'll check that out.Putty

I'll check that out.

Putty does have copy and paste.
Highlight something with the mouse and hit ctrl-c to copy and then you can paste anywhere in windows.
If you have text already cut to the clipboard you can right-click and it will paste it. If you want to cut and paste inside the putty window then just highlight the text you want to copy and then right-click at the prompt.

If you liked this post, you'll love The Open Source Ministry Forum
And, the Open Source Ministry Blog {

Joined: 11/28/2008
Nice post, in

Nice post, in addition:

Telnet is very very old and insecure technology. Try this from two machines simultaneously:

on machine1:
machine1$ telnet machine2
Username: lala
Password: lolo

on machine 2:
machine2# tethereal port 23 (or snoop, or any sniffer for that matter)
...
...
this will show you all the characters that you are typing
...
...

You definitely don't want that accross the network.

As with SSH, you can see that there are traffic going on, but it is encrypted. Not to say that this info can't be hijacked ... very difficult. Aside from that, SSH got a neat feature of port forwarding. I'm not going to discuss that as it is already covered on the net pretty nice ...

hope this helps.

rhoy

btw,
i use secureCRT for SSH and/or cygwin on my windows box as a client & a server.
of course, the linux boxes are running openssh /wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" />

--- John 3:16
For God so loved the world that he gave his one and only Son, that whoever believes in him shall not perish but have eternal life.

http://odnalor.org

Joined: 11/28/2008
Telnet is an insecure
QUOTE
Telnet is an insecure way of accessing the server command line and is therefore not an option. SSH (Secure Shell) is a secure replacement for Telnet which gives the same type of access.

Yep, that is why I included this. I included telnet in the description since there are some who still refer to ssh as telnet.

If you liked this post, you'll love The Open Source Ministry Forum
And, the Open Source Ministry Blog {

Joined: 11/28/2008
MrHerald @ May 2 2004,
QUOTE(MrHerald @ May 2 2004, 06:40 PM)
I'll check that out.

Putty does have copy and paste.
Highlight something with the mouse and hit ctrl-c to copy and then you can paste anywhere in windows.
If you have text already cut to the clipboard you can right-click and it will paste it. If you want to cut and paste inside the putty window then just highlight the text you want to copy and then right-click at the prompt.

Aahh, so it does /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />

Though when I did Ctrl-C it entered ^C<enter> into the shell (it did copy it as well), which is a bit ugly.

Paul

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified

Joined: 11/28/2008
Actually in putty all you

Actually in putty all you have to do to copy is highlight the text. That places it in the clipboard. To paste into the same or another putty session, right click by default. You can also set it up to emulate an xterm and use the middle button for paste. Use your normal paste commands to paste anywhere else.

Church Content Management -- ChurchContent.com

Joined: 11/28/2008
So that explains it! Thanks

So that explains it! Thanks Tim! Good having you here!

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified

Joined: 11/28/2008
You missed a couple of

You missed a couple of commands that are useful:
cp for copying files.
mv for moving or renaming files.
tail can be a good one if you want to looks at the last part or a big log file or
cat if you want to display the file onscreen without the editor.
The | (pipe command) is also very useful particularly for things like this:
ls -l | less which pauses your output
Of course, find and grep are great too.

Another useful and dangerous one is rm -R /directory which recursively removes the whole directory files and all. Useful because by default rmdir will not remove a directory that is not empty.

Want to Make $$$$ with your Computer? No Risk! Simply press shift-4 four times in a row

Joined: 11/28/2008
I often forget about mv and

I often forget about mv and cp. I get lazy and just move the files around in ftp while doing the other stuff in SSH. /biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" />

I guess I have been using GUIs too much and lost the love of commandline that I had when I prefered DOS over Windows for most functions.

I'll add those into the main post later. Anybody have other suggestions?

If you liked this post, you'll love The Open Source Ministry Forum
And, the Open Source Ministry Blog {

Joined: 11/28/2008
You might also mention the

You might also mention the tab key which completes the command and/or filename for you and the Up Arrow which gives you your most recently used commands.

I am kind of the opposite about GUI's in 'nix. I never use them.

Want to Make $$$$ with your Computer? No Risk! Simply press shift-4 four times in a row

Joined: 11/28/2008
I am typically logged into

I am typically logged into ftp with smartftp when I am managing files and I just prefer the drag and drop and being able to view the full tree.

If you liked this post, you'll love The Open Source Ministry Forum
And, the Open Source Ministry Blog {

Joined: 11/28/2008
Don't forget chmod and chown!

Don't forget chmod and chown! Two very important commands! (well, maybe not chown so much, but chmod is essential!)

--
iLuke

Joined: 09/11/2008
SSH and command line in osx terminal

Hey everyone,

MrHerald: Great tutorial! Thanks!

I am using Cyberduck. It was great, at first, so I could get the "feel" of things. But it's nearly driven me INSANE because, in order to delete a file, I shows a status that: "listing file...reading permission....listing...blah, blah, blah. Which isn't so bad...UNLESS you have a lot of files to delete.

I wound up totally breaking my test site. And I nearly went nuts while Cyberduck took like 2 hours to delete stuff...utterly slow connection doesn't help!

So I decided to finally get SERIOUS with the command line. Since my site was broken, then I figured I couldn't do any damage. Apart from being "rusty" on some of the commands, I had everything deleted in no time!

Maybe there is some option, in Cyberduck, to disable all those annoying status listing and just do the command. But I think I'll start concentrating more on ssh!

Same thing with vim. I had to look up some commands, but it was a nice thing to just type something up really quick for index.html

Thanks again to everyone,
Shane