breaking into the unknown…

ssh to remote server

Leave a comment

we will ssh to server represented by system B from the local machine represented by system A. The detail of the two system is as below

system A :
name :  arun@
username: arun
password: axyz

system B :
name :  kapil@
username: kapil
password: axyz


1 -> ssh client and server should be installed on both the machine. Install them with below command

$sudo apt-get install openssh-client
$sudo apt-get install openssh-server

2 -> modifying ssh-server configuration on server machine i,e system B for us

Though , default works fine, It is better to look at the file to see what going on. login to system B
$sudo gedit /etc/ssh/sshd_config # it will open the configuration file for you

Below, are the some line, I felt worth describing

Port 22 # this is the default setting, when some one ssh to your system, they listen to this port by default. You can change it to some other value, which will make your server more secure as while doing ssh the person also need to pass the port no.

PubkeyAuthentication yes # If you do not want anyone to login directly with valid ssh key, but only with password set it to no

PermitRootLogin yes #set it to no, if you do not want to give root access to ssh login

after making the changes you need to start the ssh server with the below command

$sudo /etc/init.d/ssh restart

NOTE : You better backup this file before making any changes. if you make some mistake in syntex or some other things , sshd server will refuses to start due to an incorrect configuration directive. In worst case, If you have access to server only through ssh, then you will not able to login to server to correct the error i,e your server get locked for you after restart, if you make error in sshd_config file.

3-> ssh key should be available on bot the machine. run below command to generate them
$ssh-keygen -t dsa # keep pressing enter when asked for password etc
By default the public key is saved in the file ~/.ssh/, while ~/.ssh/id_dsa is the private key
we will ssh to our server(i,e system B)  from system A
-> Login with password

arun@arun-yadav:~$ ssh kapil@
kapil@’s password: kxyz
Welcome to Ubuntu 12.04.1 LTS (GNU/Linux 3.2.0-31-generic-pae i686)
* Documentation:
155 packages can be updated.
60 updates are security updates.
Last login: Wed Oct 31 14:14:49 2012 from arun-yadav.local
kapil@f3-MS-7636:~$ # so you are loged in to server

-> Login directly with ssh

for this you need to create a  authorized_keys file on ssh folder of server i,e /.ssh/authorized_keys and append your key content to it. provided, authorized_keys file exist in ssh folder of server(create it if it is not there and give it 600 permission) you can copy your to it with the below command from your local machine i,e the system A

$ ssh-copy-id kapil@
kapil@’s password: # you will get the below message
Now try logging into the machine, with “ssh ‘kapil@′”, and check in:
to make sure we haven’t added extra keys that you weren’t expecting.
So, now when you do ssh, you will be directly loged in as you can see below
arun@arun-yadav:~$ ssh kapil@
Welcome to Ubuntu 12.04.1 LTS (GNU/Linux 3.2.0-31-generic-pae i686)
* Documentation:
155 packages can be updated.
60 updates are security updates.
Last login: Wed Oct 31 14:18:48 2012 from arun-yadav.local
kapil@f3-MS-7636:~$   #so you are directly loged in to the server


Author: arunyadav4u

over 7 years experience in web development with Ruby on Rails.Involved in all stage of development lifecycle : requirement gathering, planing, coding, deployment & Knowledge transfer. I can adept to any situation, mixup very easily with people & can be a great friend.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s