Working with SSH

This site has been moved to “requesttutorial.com

Hello Readers

I will be working on Ubuntu 12.04 to setup ssh server but you can apply the same principle to all of Linux versions. so lets get going…

Installation:

sudo apt-get install ssh

Start Server

To start the service type

sudo service start ssh

or

sudo /etc/inid.d/sshd start

Login to client

Once you are done, Now you want to connect to client or remote system type

ssh username@clientIP

e.g. as in the image below

login_ssh

Now you can are logged in and you can type all sort of commands like ls and nano to edit files.

Access Graphical Interface/Utilities:

Another handy feature of ssh you would love is that you can access the graphical utility e.g if you want to use gedit of the remote computer instead of nano or you want to browse the file system. To do this you will have to login with the -X parameter. To do this

ssh -X username@<client’s IP> and hit enter and now you can use the graphical utilities as well e.g.

To browse the filesystem…

sudo nautilus

or

gedit somefile.txt

This will open gedit on remote system and present it to you as shown in image below

ssh-x

Setting up Keys to login in to remote system:

To login without password, you need to setup public private keys and then copy the public key to the server and keep the private key with your self. The holder of the private key can login in to the system without password.

To generate the keys, type

ssh-keygen -t rsa

If the keys already exists, you will be asked to replace them, choose whether you want to replace them or not.

You will be prompt to enter a pass-phrase, This isn’t the system password but its the password to unlock the key (you will be prompt everything you use the key, This is for protection against key-theft), Just press Enter if you dont want to Enter any Key.

Your generated Keys will be saved in /home/<user>/.ssh directory

gen-key

Now there will be two files in .ssh folder (the folder will be created automatically)

id_rsa (private Key)
id_rsa.pud (public key)

To copy key to the server type the command

ssh-copy-id username@server-ip

check-loggin

or

scp .ssh/id_rsa.pud username@server-ip:/home/<user>/.ssh

on server

mkdir .ssh
cat id_rsa.pub > authorized_keys

now to connect to the server, type

ssh username@server-ip

Note:

If you get an error like “Agent admitted failure to sign using the Key”

ssh-error

To Fix this problem, issue the following command to fix this problem

ssh-add

ssh-add

Another solution is by issuing the following command to login

ssh -i .ssh/id_rsa username@server-ip

For Windows users:

One solution to connect to a Linux server is to use putty but I prefer MobaXterm that is far better then putty and handles all the detail I mentioned above seamlessly, Click here to Download MobaXterm. If has a pretty neat and easy to use GUI and Its not just a ssh client but do alot of other interesting stuff. Its a one window service to all your server. Go ahead and explore it your self.

Advertisements

2 thoughts on “Working with SSH

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s