Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Well im trying to connect to a client machine using ssh using this command

ssh root@ip-of-server

It immediately slaps me with this error

ssh: connect to host xxx.xxx.xxx.xxx port 22: Connection refused

Then I tried to access a local server using same command it worked.

For further experiment I tried to do

ssh umair@127.0.0.1

It displayed the same error

Whats wrong here. Any suggestion

share|improve this question
    
On your machine you are trying to connect from, in reference to the last error, do you have openssh-server or sshd installed? On the remote server, is sshd running? If there is a NAT or router, are all appropriate ports forwarded? –  hexafraction Nov 4 '12 at 14:23
    
well last error ssh umair@127.0.0.1 is of Ubuntu installed on laptop. Plus how do i know that which One do I have OPENSSH-SERVER or SSHD. –  OmiPenguin Nov 4 '12 at 14:28
1  
Just go into Synaptic and see whether either are installed. It doesn't matter which is installed as long as one of them is. Same applies to the remote server. Please also check port forwarding there. –  hexafraction Nov 4 '12 at 14:29
    
Ok i solved it actually i didnt passed the port no. **But it raised another question that When i tried to access the Local server without passing the port no it was still connected Y IS THAT??? ** –  OmiPenguin Nov 5 '12 at 8:14
1  
Umm... because the remote server is on a different port than the default? –  hexafraction Nov 5 '12 at 11:26
show 2 more comments

2 Answers 2

up vote 3 down vote accepted

The remote server appears to operate on a different port than the default(22). You need to specify it using ssh user@host -p port syntax. It works locally since the port is the default, which is 22. The server and local server both require a package to provide SSH server, sshd or openssh. They can be installed with:

sudo apt-get install openssh-server

or

sudo apt-get install sshd
share|improve this answer
add comment

You need to have openssh server running on the remote host to which your trying to connect.

On the remote host: sudo apt-get install openssh-server on the remote host. IT generates the rsa/dsa keys and places them in /etc/ssh

Post install, run ssh-keygen to generate pub and priv keys copied to id_rsa and id_rsa.pub respectively. These files are placed into a .ssh folder which it creates when you run this command.

And then copy the contents of your id_rsa.pub into authorized_keys Navigate to $HOME/.ssh , then run, cat id_rsa.pub >> authorized_keys

The known_hosts file is auto generated when you first try : ssh localhost or to any other host.

Note that, the permissions of id_rsa.pub and known_hosts file alone should be readable by group and others.

Now from your local machine: ssh-copy-id -i $HOME/.ssh/id_rsa.pub yourremotehostname

It would ask for Yes/No, give a 'Yes'.

Next time you try ssh yourremotehostname, it would merrily log you in w/o asking you a password.

Hope this helps.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.