Login | Sitemap | Home arrow How-to

An easy how to use ssh and scp for Linux beginners Print

Simple and easy usage of SSH in your Linux network.


ssh stand for secure shell and is used to securely login to a Linux / UNIX host running the sshd daemon on a reachable network.

Note: If you want to connect to a  host which is behind a firewall you will have to open up the following on the firewall protecting that host:
Port: 22 and protocol type: TCP

Standard every day usage of the ssh client is quite simple.
For the following examples we will call our user “john” who is located on a computer which we will call “computer.local” and the host he wants to connect to “server.local”. If we use names instead of IP addresses you assume that DNS name resolution is setup on the network

The user account “john” must be on every host you want to connect to.

Connecting to another computer.

john needs to connect to another linux host (as above called server) with the IP 192.168.0.1.
This is how he dose it from the linux command line (shell) – john will need to know his password:
#: ssh server.local or
#: ssh 198.168.0.1or
#: ssh This e-mail address is being protected from spam bots, you need JavaScript enabled to view it or
#: ssh This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
But if john wants to connect to the same server but as root then it would be as follows - john will need to know root's password!:
#: ssh This e-mail address is being protected from spam bots, you need JavaScript enabled to view it or
#: ssh This e-mail address is being protected from spam bots, you need JavaScript enabled to view it

Copy Files & Directories.

ssh can also be used to copy files & directories, and as you can imagine this is also very simple using  the same connection method as above. but the command we use is now scp and not ssh.
Example1: john wants to copy a file called bigfile.log from his “computer” to the “server”:
This will copy  bigfile.log from its current location on johns's computer to johns home directory on “server”. 
#: scp  bigfile.log server.local:
Example1: To copy the same file but from /var/log on “computer” to /tmp on “server”
#: scp  /var/log/bigfile.log server.local:/tmp
as root
#: scp  /var/log/bigfile.log This e-mail address is being protected from spam bots, you need JavaScript enabled to view it :/tmp


Example2: Now john wants to copy the file back from “server” after editing it and put is in a directory called “logs” in his home directory.

#: scp  server.local:/tmp/bigfile.log ~/logs
as root
#: scp  This e-mail address is being protected from spam bots, you need JavaScript enabled to view it :/tmp/bigfile.log ~john/logs


Example3: john is now getting ambitions and wants to copy a whole directory called “my_website” from his home directory on “computer” to the web server root directory on “server” called /var/www.

#: scp -r ~/my_website server.local:/var/www/
as root
#: scp -r ~/my_website This e-mail address is being protected from spam bots, you need JavaScript enabled to view it :/var/www/

Or just the files & sub directories from  my_website to the web server's root directory on “server”

#: scp -r ~/my_website/* server.local:/var/www/
as root
#: scp -r ~/my_website/* This e-mail address is being protected from spam bots, you need JavaScript enabled to view it :/var/www/

Public Key Authentication

Now that we know how to do simple logins and file copies with ssh using passwords, we can do all the same but without having to type in a password at the prompt, using “public key authentication” sounds fancy..., it is fancy! And is also very easy to setup as you can imagine.

 

Come back soon! We will updated this in the next day or so....

Last Updated ( Friday, 19 September 2008 )