LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   SSH: Connection Refused - Ubuntu 12.04 (https://www.linuxquestions.org/questions/linux-server-73/ssh-connection-refused-ubuntu-12-04-a-4175413901/)

TechHunter16 06-28-2012 04:09 PM

SSH: Connection Refused - Ubuntu 12.04
 
I'm setting up an SSH server on my home computer. I'm kind of a Linux noob (I've been using Ubuntu since Febuary or so, meaning I'm not terribly good at everything, but I know some basic stuff to try.

So, if I try to connect to the server through my laptop (also running Ubuntu 12.04), I get this error:
Code:

$ ssh 192.168.1.7 -vvv
OpenSSH_5.9p1 Debian-5ubuntu1, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug3: cipher ok: aes128-ctr [aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc]
debug3: cipher ok: aes192-ctr [aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc]
debug3: cipher ok: aes256-ctr [aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc]
debug3: cipher ok: arcfour256 [aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc]
debug3: cipher ok: arcfour128 [aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc]
debug3: cipher ok: aes128-cbc [aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc]
debug3: cipher ok: 3des-cbc [aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc]
debug3: ciphers ok: [aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc]
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.1.7 [192.168.1.7] port 22.
debug1: connect to address 192.168.1.7 port 22: Connection refused
ssh: connect to host 192.168.1.7 port 22: Connection refused

If I connect to it through itself (localhost), I get this:

Code:

$ ssh localhost -vvv
OpenSSH_5.9p1 Debian-5ubuntu1, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: connect to address 127.0.0.1 port 22: Connection refused
ssh: connect to host localhost port 22: Connection refused

Here's some proof that it's running:
Code:

ps -ef | grep sshd
[my account]  30534 27324  0 17:06 pts/0    00:00:00 grep --color=auto sshd

Could someone please give me some advice? Any help is appreciated.

Thanks.

eSelix 06-28-2012 04:21 PM

Quote:

ps -ef | grep sshd
[my account] 30534 27324 0 17:06 pts/0 00:00:00 grep --color=auto sshd
It is proof that it is not running. You see "00:00:00 grep ....." on output? - it means that "grep" with some options is running, you piped it in last command. So check if you have server installed - it is in package "openssh-server" or just "ssh".

Kustom42 06-28-2012 04:23 PM

Ok well there are two ssh config files.. ssh_config is the [I]client/I] configuration file and your sshd_config is the daemon or server configuration file. So ssh is running but your looking at a connectivity issue.

Take a look and see if your server is listening on port 22:
Code:

netstat -anp | grep :22
Verify that sshd is running, run the following as root:
Code:

ps aux | grep sshd | grep root | grep -v "grep"

# You should see something like /usr/sbin/sshd for the process.
# If you see other processes or just a single process as "sshd: username" that is an established ssh session

/etc/init.d/sshd status

Let us know what the results of that are before you go much more deeper. The next steps would be to review your sshd_config file and take a look at firewall rules

Kustom42 06-28-2012 04:24 PM

Quote:

Originally Posted by eSelix (Post 4714468)
It is proof that it is not running. You see "00:00:00 grep ....." on output? - it means that "grep" with some options is running, you piped it in last command. So check if you have server installed - it is in package "openssh-server" or just "ssh".


You should check with the /etc/init.d/ script as it has the best functionality built in to check. The ps command should give the /usr/sbin/sshd process running but the init script would confirm that it is not running.

ArcLinux 06-28-2012 04:53 PM

This may be a dumb question, but is it installed? openssh-server?

Noway2 06-28-2012 06:33 PM

Your SSHD (server) is not running. If it were running you would see something like the following:
Code:

sudo ps -ef | grep sshd
[sudo] password for user:
root      1072    1  0 Jun22 ?        00:00:00 /usr/sbin/sshd -D
root    25590  1072  0 19:28 ?        00:00:00 sshd: user [priv] 
user    25668 25590  0 19:28 ?        00:00:00 sshd: user@pts/0   
user    25690 25669  1 19:28 pts/0    00:00:00 grep sshd

I agree with Arclinux, is SSHD installed? What do you get if you enter:
Code:

sudo ssh status
If you don't see it running, try
Code:

sudo ssh start
You will probably find that it is either not installed or you have an error in your configuration file that keeps it from starting. If you get an error indicating the latter, looking in /var/log/syslog should give you the error line/location to debug it.

TechHunter16 06-28-2012 08:04 PM

Thanks for all of the replies.
Quote:

Code:

ps -ef | grep sshd
[my account] 30534 27324 0 17:06 pts/0 00:00:00 grep --color=auto sshd

It is proof that it is not running. You see "00:00:00 grep ....." on output? - it means that "grep" with some options is running, you piped it in last command. So check if you have server installed - it is in package "openssh-server" or just "ssh".
I definitly have it installed. I've looked in the configs. Also, I was able to connect to it before, but then it stopped working.

Quote:

Ok well there are two ssh config files.. ssh_config is the [I]client/I] configuration file and your sshd_config is the daemon or server configuration file. So ssh is running but your looking at a connectivity issue.

Take a look and see if your server is listening on port 22:
Code:

netstat -anp | grep :22

Verify that sshd is running, run the following as root:

Code:

ps aux | grep sshd | grep root | grep -v "grep"

# You should see something like /usr/sbin/sshd for the process.
# If you see other processes or just a single process as "sshd: username" that is an established ssh session

/etc/init.d/sshd status

Let us know what the results of that are before you go much more deeper. The next steps would be to review your sshd_config file and take a look at firewall rules
For the first and second commands, it doesn't return anything. For the third, I get this:
Code:

-bash: /etc/init.d/sshd: No such file or directory
Not completely sure what you mean by your second post. Sorry for my noobishness.

Quote:

Your SSHD (server) is not running. If it were running you would see something like the following:
Code:


sudo ps -ef | grep sshd
[sudo] password for user:
root      1072    1  0 Jun22 ?        00:00:00 /usr/sbin/sshd -D
root    25590  1072  0 19:28 ?        00:00:00 sshd: user [priv] 
user    25668 25590  0 19:28 ?        00:00:00 sshd: user@pts/0   
user    25690 25669  1 19:28 pts/0    00:00:00 grep sshd

I agree with Arclinux, is SSHD installed? What do you get if you enter:

Code:

sudo ssh status
If you don't see it running, try

Code:

sudo ssh start
You will probably find that it is either not installed or you have an error in your configuration file that keeps it from starting. If you get an error indicating the latter, looking in /var/log/syslog should give you the error line/location to debug it.
Well, when I run either of the commands you listed, I get this error:

Code:

ssh: Could not resolve hostname stop: Name or service not known
But, if I run it like this, I get the following:
Code:

# start ssh
ssh start/running, process 31905

If I stop it the same way, I get this:
Code:

# stop ssh
stop: Unknown instance:

Thanks again for all of the replies.

Noway2 06-29-2012 04:26 AM

Quote:

ssh: Could not resolve hostname stop: Name or service not known
My bad, I left out a word in the command. It should have been:
Code:

sudo service ssh status and service ssh start
you can also use the full command to the init script:
sudo /etc/init.d/ssh start

Regarding this error:
Quote:

-bash: /etc/init.d/sshd: No such file or directory
In Ubuntu the init script is ssh, not sshd. This is distribution specific, for example in Centos it is /etc/init.d/sshd

eSelix 06-29-2012 07:31 AM

Try to start ssh with this command:
Code:

/usr/sbin/sshd -ddd
There should be a reason why it cannot start at the end. If it start however, then post your /etc/init/ssh.conf and check of existence "/etc/ssh/sshd_not_to_be_run" or "/dev/null" and check "/var/log/syslog" after trying command "start ssh".

TechHunter16 06-29-2012 08:00 AM

Quote:

ssh: Could not resolve hostname stop: Name or service not known
My bad, I left out a word in the command. It should have been:
Code:

sudo service ssh status and service ssh start
you can also use the full command to the init script:
sudo /etc/init.d/ssh start

Regarding this error:
Code:

-bash: /etc/init.d/sshd: No such file or directory
In Ubuntu the init script is ssh, not sshd. This is distribution specific, for example in Centos it is /etc/init.d/sshd
Okay, first command outputted this:
Code:

status: Env must be KEY=VALUE pairs
For the init scrpit, I get this:
Code:

Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service ssh start

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start ssh

So, I've basically already done that. I'm assuming that is a distro-specific thing also?

Quote:

Try to start ssh with this command:
Code:

/usr/sbin/sshd -ddd
There should be a reason why it cannot start at the end. If it start however, then post your /etc/init/ssh.conf and check of existence "/etc/ssh/sshd_not_to_be_run" or "/dev/null" and check "/var/log/syslog" after trying command "start ssh".
Okay, so no, it does not run, and by the looks of it, it seems to be bad config.:
Code:

$ /usr/sbin/sshd -ddd
debug2: load_server_config: filename /etc/ssh/sshd_config
debug2: load_server_config: done config len = 819
debug2: parse_server_config: config /etc/ssh/sshd_config len 819
debug3: /etc/ssh/sshd_config:5 setting Port 22
debug3: /etc/ssh/sshd_config:9 setting Protocol 2
debug3: /etc/ssh/sshd_config:11 setting HostKey /etc/ssh/ssh_host_rsa_key
debug3: /etc/ssh/sshd_config:12 setting HostKey /etc/ssh/ssh_host_dsa_key
debug3: /etc/ssh/sshd_config:13 setting HostKey /etc/ssh/ssh_host_ecdsa_key
debug3: /etc/ssh/sshd_config:15 setting UsePrivilegeSeparation yes
debug3: /etc/ssh/sshd_config:26 setting LoginGraceTime 1m
debug3: /etc/ssh/sshd_config:27 setting PermitRootLogin no
debug3: /etc/ssh/sshd_config:30 setting RSAAuthentication yes
debug3: /etc/ssh/sshd_config:31 setting PubkeyAuthentication yes
debug3: /etc/ssh/sshd_config:32 setting AuthorizedKeysFile %h/.ssh/authorized_keys2
debug3: /etc/ssh/sshd_config:35 setting IgnoreRhosts yes
debug3: /etc/ssh/sshd_config:37 setting RhostsRSAAuthentication yes
debug3: /etc/ssh/sshd_config:39 setting HostbasedAuthentication no
debug3: /etc/ssh/sshd_config:44 setting PermitEmptyPasswords no
debug3: /etc/ssh/sshd_config:48 setting ChallengeResponseAuthentication no
debug3: /etc/ssh/sshd_config:51 setting PasswordAuthentication yes
debug3: /etc/ssh/sshd_config:60 setting GSSAPIAuthentication yes
debug3: /etc/ssh/sshd_config:63 setting X11Forwarding yes
debug3: /etc/ssh/sshd_config:64 setting X11DisplayOffset 10
debug3: /etc/ssh/sshd_config:65 setting PrintMotd no
debug3: /etc/ssh/sshd_config:66 setting PrintLastLog no
debug3: /etc/ssh/sshd_config:67 setting TCPKeepAlive yes
debug3: /etc/ssh/sshd_config:74 setting AcceptEnv LANG LC_*
debug3: /etc/ssh/sshd_config:76 setting Subsystem sftp /usr/lib/openssh/sftp-server
debug3: /etc/ssh/sshd_config:87 setting UsePAM yes
debug3: /etc/ssh/sshd_config:89 setting AllowTcpForwarding yes
debug3: /etc/ssh/sshd_config:90 setting GatewayPorts yes
debug3: /etc/ssh/sshd_config:91 setting AllowUsers jeremy
debug3: /etc/ssh/sshd_config:92 setting ClientAliveInterval 60
debug3: /etc/ssh/sshd_config:93 setting ClientAliveCountMax 0
/etc/ssh/sshd_config: line 94: Bad configuration option: ForwardAgent
debug3: /etc/ssh/sshd_config:94 setting ForwardAgent yes
/etc/ssh/sshd_config: line 95: Bad configuration option: ForwardX11
debug3: /etc/ssh/sshd_config:95 setting ForwardX11 yes
/etc/ssh/sshd_config: terminating, 2 bad configuration options

So, I decided to comment out the config options I had added in sshd_config:
Code:

debug2: load_server_config: filename /etc/ssh/sshd_config
debug2: load_server_config: done config len = 691
debug2: parse_server_config: config /etc/ssh/sshd_config len 691
debug3: /etc/ssh/sshd_config:5 setting Port 22
debug3: /etc/ssh/sshd_config:9 setting Protocol 2
debug3: /etc/ssh/sshd_config:11 setting HostKey /etc/ssh/ssh_host_rsa_key
debug3: /etc/ssh/sshd_config:12 setting HostKey /etc/ssh/ssh_host_dsa_key
debug3: /etc/ssh/sshd_config:13 setting HostKey /etc/ssh/ssh_host_ecdsa_key
debug3: /etc/ssh/sshd_config:15 setting UsePrivilegeSeparation yes
debug3: /etc/ssh/sshd_config:26 setting LoginGraceTime 1m
debug3: /etc/ssh/sshd_config:27 setting PermitRootLogin no
debug3: /etc/ssh/sshd_config:30 setting RSAAuthentication yes
debug3: /etc/ssh/sshd_config:31 setting PubkeyAuthentication yes
debug3: /etc/ssh/sshd_config:32 setting AuthorizedKeysFile %h/.ssh/authorized_keys2
debug3: /etc/ssh/sshd_config:35 setting IgnoreRhosts yes
debug3: /etc/ssh/sshd_config:37 setting RhostsRSAAuthentication yes
debug3: /etc/ssh/sshd_config:39 setting HostbasedAuthentication no
debug3: /etc/ssh/sshd_config:44 setting PermitEmptyPasswords no
debug3: /etc/ssh/sshd_config:48 setting ChallengeResponseAuthentication no
debug3: /etc/ssh/sshd_config:51 setting PasswordAuthentication yes
debug3: /etc/ssh/sshd_config:60 setting GSSAPIAuthentication yes
debug3: /etc/ssh/sshd_config:63 setting X11Forwarding yes
debug3: /etc/ssh/sshd_config:64 setting X11DisplayOffset 10
debug3: /etc/ssh/sshd_config:65 setting PrintMotd no
debug3: /etc/ssh/sshd_config:66 setting PrintLastLog no
debug3: /etc/ssh/sshd_config:67 setting TCPKeepAlive yes
debug3: /etc/ssh/sshd_config:74 setting AcceptEnv LANG LC_*
debug3: /etc/ssh/sshd_config:76 setting Subsystem sftp /usr/lib/openssh/sftp-server
debug3: /etc/ssh/sshd_config:87 setting UsePAM yes
debug1: sshd version OpenSSH_5.9p1 Debian-5ubuntu1
debug1: could not open key file '/etc/ssh/ssh_host_rsa_key': Permission denied
Could not load host key: /etc/ssh/ssh_host_rsa_key
debug1: could not open key file '/etc/ssh/ssh_host_dsa_key': Permission denied
Could not load host key: /etc/ssh/ssh_host_dsa_key
debug1: could not open key file '/etc/ssh/ssh_host_ecdsa_key': Permission denied
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
debug1: setgroups() failed: Operation not permitted
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-ddd'
debug3: oom_adjust_setup
Set /proc/self/oom_score_adj from 0 to -1000
debug2: fd 3 setting O_NONBLOCK
debug1: Bind to port 22 on 0.0.0.0.
Bind to port 22 on 0.0.0.0 failed: Permission denied.
debug2: fd 3 setting O_NONBLOCK
debug3: sock_set_v6only: set socket 3 IPV6_V6ONLY
debug1: Bind to port 22 on ::.
Bind to port 22 on :: failed: Permission denied.
Cannot bind any address.

Note: after today, I will not have access to the server computer for another five days, so any suggestions will have to be tested on Tuesday.

grim76 06-29-2012 08:03 AM

Looks like you are trying to run sshd as a normal user. You will have to start it as root for it to bind to port 22.

Noway2 06-29-2012 08:30 AM

Quote:

status: Env must be KEY=VALUE pairs
The "and" was not meant to be part of the command. In my first post to this thread, I said "sudo ssh status" which should have been sudo service ssh status" and if you didn't see it report a pid indicating that it was running, try "sudo ssh start", which should have been "sudo service ssh start".

In any case, you have confirmed that it is not running and your log files are indicating a problem with your configuration file, which appears to be caused by options you have added.
Quote:

You will have to start it as root for it to bind to port 22.
Correct, but as a point of clarification for your distribution: in order to start your SSH server as root in ubunutu you will need to prefix the command with SUDO (super user do) because Ubuntu disables the 'root' account. The reason is that ports below 1024 are considered privileged and are off limits to normal users. During normal startup this is not a problem as the init scripts, one of which starts SSH, are launched with root permissions.

One other thing to mention, you think it is running, you can verify that the process is active and listening using the netstat command:
Code:

sudo netsat -pane | grep 22
which should give you output with a line like the following:
Code:

tcp        0      0 0.0.0.0:22              0.0.0.0:*              LISTEN      0          3707        1072/sshd

TechHunter16 06-29-2012 02:11 PM

Interesting... I'll have to check that out when I get access to the computer again.

jsaravana87 06-30-2012 01:21 AM

Hi
check the sshd.pid permission .It may leads ssh startup error

#stat /var/run/sshd.pid
File: `/var/run/sshd.pid'
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 11h/17d Inode: 3979 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-06-29 10:53:36.982798375 +0530
Modify: 2012-06-29 10:53:36.982798375 +0530
Change: 2012-06-29 10:53:36.982798375 +0530

eSelix 07-01-2012 09:49 AM

I believe your server didn't work by these bad configuration options. And next "Permission denied" errors were, because you trying to run server on non root account, as other noticed. Check if it still doesn't start after reboot by ps or netstat. If not then once again show output of "/usr/sbin/sshd -ddd".

By the way these options "ForwardAgent" and "ForwardX11" are for ssh client configuration (/etc/ssh/ssh_config), not server. For server there is "X11Forwarding" option.


All times are GMT -5. The time now is 11:11 PM.