I am connecting to CentOS7 minimal installation machine in a LAN (192.168.1.33).
I have changed the ssh port vi /etc/ssh/sshd_config line 17 Port 1234
after restarting the sshd service the connection is refused
ssh demo#192.168.1.33 -p 1234
ssh: connect to host 192.168.1.33 port 1234: Connection refused
I have disabled SELinux and router-firewall but still having problem.
Though if I change back to port 22 I can login again.
Is there any other configuration to be changed?
Can you remotely connect to the server another way? If so, once you get in, run sudo netstat -plutn.
You should see at least one entry for sshd. If you don't, sshd isn't running. You can install it via sudo apt-get install openssh-server.
If you do, is the port under 'Local Address' for the sshd line 1234? This will tell you if you successfully changed the port configuration.
Hope that helps!
Related
I'm running a raspberry pi in a remote location, so I setup a reverse ssh tunnel to one of my servers (CentOS 7) using autossh. All works fine, I can use this reverse ssh to login to the Raspberry from the server, but I can't get the server to forward the ssh, so I can not connect to the Raspberry via the server from the laptop, I always get Connection Refused.
Firewall on the server has been shut down the GatewayPorts yes has been added to the sshd_config and sshd restarted.
Details:
On the Raspberry I'm opening the reverse SSh tunnel:
autossh -fNC -g -M 0 -R 2223:localhost:22 [serveruser]#[server] -p2002
From the server I can ssh into the Raspberry with no problem:
ssh [raspberryuser]#localhost -p2223
I have added the next to /etc/ssh/sshd_config and restarted sshd service after:
GatewayPorts yes
I can successfully ssh into the Raspberry from the server:
ssh [raspberryuser]#localhost -p2223
But when I'm trying to connect from my laptop to the Raspberry through this server:
ssh [raspberryuser]#[server] -p2223
ssh: connect to host [server] port 2223: Connection refused
The firewall on the server has been stopped
SELinux is disabled on the server
I ran out of ideas, so I'm open to suggestions
This isn't really an answer, but after restarting the server (CentOS 7), now I can connect to the Raspberry from my laptop via the server, don't receive "connection refused" anymore.
The only explanation what I have that the SSHD did not restart when I tried to restart it, although the 'messages' logs clearly shows that it was restarted repeatedly:
Dec 4 08:54:54 xxx systemd: Stopping OpenSSH server daemon...
Dec 4 08:54:54 xxx systemd: Starting OpenSSH server daemon...
In any way, the full reboot of the server has resolved it.
I set up SSH on my Ubuntu server (running XMonad) and generated a key for my laptop that I used to connect to my home server with. I also went on my wireless router and forward port 22 for SSH use. I can SSH fine when I'm at home using the standard:
ssh user#ipaddress
However when I'm outside of my local network I get this error:
ssh: connect to host xxx.xx.xx.xxx port 22: Connection refused
Everything I read says I need to either a) check that my port 22 is forward (which it is) or b) check that sshd is actually running on my Ubuntu server (which it is).
Any ideas what is preventing my SSH from working when I'm remote?
Add the following line your ssh user config file if it doesn't exits You can create the config file as shown below.
vi ~/.ssh/config
Host *
ServerAliveInterval 300
Change the permission as below:
chmod 600 ~/.ssh/config
Restart the daemon. Hope this helps.
https://serverfault.com/a/371563/617303
For me this was the cause.
In your /etc/ssh/sshd_config or /etc/ssh_ssh_config check to make sure GSSAPI Auth is disabled (set to no).
GSSAPIAuthentication no
Then restart the service or machine.
I am not able to access Amazon EC2 instance via ssh as i am behind a firewall.
So, i thought of running ssh on port other than 22, like 80 or 443.
I tried starting Amazon EC2 instance via Web Management Console with following 'user data':
#!/bin/bash -ex
perl -pi -e 's/^#?Port 22$/Port 80/' /etc/ssh/sshd_config
service sshd restart || service ssh restart
The idea being that the above script would execute on instance startup and switch ssh from port 22 to port 80. (Ref: http://alestic.com/2010/12/ec2-ssh-port-80)
But ssh is still not accessible on port 80.
Apparently 'user data' script is not being executed on start up?
I can 'only' start stop instances via Web Management Console, not from command-line (being behind firewall)
Any ideas?
To connect to an AWS instance through ssh from a port different than default 22:
Open the security group of your instance so that it allows connections to that port from the source that you choose (0.0.0.0/0 for any source).
In your instance:
It is a new instance you could use an user-data script like this one:
#!/bin/bash -ex
perl -pi -e 's/^#?Port 22$/Port 443/' /etc/ssh/sshd_config
service sshd restart || service ssh restart
Please note that this only works if you are launching a new instance:
User data scripts and cloud-init directives only run during the first boot cycle when an instance is launched.
If it is not a new Instance, edit the /etc/ssh/sshd_config file adding/changing Port 22 to the port that you want (i.e: Port 443) to connect through ssh and then do service ssh restart and you should be done.
Note: I did this with an Ubuntu instance, with another Linux instances may be slightly different.
The amazon firewall blocks all ports other than 22. You first have to enable port 80/443/whatever.
HOWTO:
Go to "security groups" -> click on the group you chose for your instance, then on the "Inbound" tab.
There you can add your ports.
EDIT: If by chance you also installed apache or some other webserver, port 80 will be used and cannot be used by sshd. I do not know which operating system is installed on your server, but maybe some webserver is already included?
EDIT 2: As per the last comment, it seems nowadays all ports are blocked by default. So you will have to open port 22 if you need it. Wasn't the case eight years ago, but configurations change ;)
Here is what I came up with to run sshd on 443 and 22 having rhel8 on ec2
make sure your security groups allow connection from your network/ip to the desired ports (in my case 22 and 443)
tcp 443 1.2.3.4/32 #allow access to 443 from IP 1.2.3.4
tcp 22 1.2.3.4/32 #allow access to 22 from IP 1.2.3.4
Login to the EC2 and
#install semanage with
sudo yum install -y policycoreutils-python-utils
#delete 443 from http ports
sudo semanage port -d -t http_port_t -p tcp 443
#add 443 to ssh ports
sudo semanage port -m -t ssh_port_t -p tcp 443
Edit /etc/ssh/sshd_config
Port 22
Port 443
Restart sshd
sudo service sshd restart
I am running on Mac OS X 10.7.4.
I am unable to ssh to a remote computer, but when I do ssh user#localhost, it works fine.
The error displayed is
OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /etc/ssh_config
debug1: Applying options for *
debug1: Connecting to web.iiit.ac.in [14.139.82.8] port 22.
debug1: connect to address 14.139.82.8 port 22: Connection refused
ssh: connect to host web.iiit.ac.in port 22: Connection refused
I have enabled the root login in System Preferences and disabled firewall.
Also, ps aux | grep ssh shows ssh-agent, contains /usr/bin/ssh-agent -l and grep ssh in the output.
On doing sudo launchctl list|grep ssh it shows:
0 com.openssh.sshd
After this, sudo launchctl start com.openssh.sshd ; sudo launchctl list|grep ssh gives
45973 - com.openssh.sshd
Again, after checking sudo launchctl list|grep ssh after sometime, it again shows :
- 0 com.openssh.sshd
In system preferences -> sharing->enable remote login. It will fix it.
Wireless connections has well know problems with the SSH strict package receiving algorithm. I have the same problem with a WiMax connection. It would turn good if you can establish a VPN or any kind of tunnel to the server.
see also
this thread
Your remote host probably doesn't have an SSH server running (or, if it does, it's not listening on port 22).
Your tests (ps aux, launchctl etc) won't help - the issue is on the remote host, not the local (you've got an SSH client, because you can connect to localhost, but the remote host 14.139.82.8 isn't allowing connections on port 22).
When I ran in to this problem, I found that OpenSSH was not completely installed. Install it by typing into Terminal: sudo apt-get install openssh-client openssh-server
Also, check your firewall. The default SSH port is 22. Open that port.
clean known_hosts file and try again. Worked for me.
I have installed cygwin in windows 7 but i get the following error
$ ssh localhost
ssh: connect to host localhost port 22: Connection refused
I faced the same problem but I ran this on the CYGWIN command line and it worked :
~ : net start sshd
After that I executed the command ssh -v localhost and the error message didn't show up. Hope that this helps !.
If you are facing this problem in Windows XP follow these steps to open port for ssh:
Go to windows firewall of security section in control panel
Exceptions->add port
Give port name as ssh and number as 22.
Select option TCP
Click on Ok
This will help you open ssh from cygwin
For local application development like hadoop on windows please change the scope localhost /ip address in the custom list.
You can try to use port 23 or ask your host provider for the ssh port. Some host providers change the ssh port.
ssh user#yoursite.com -p 23
Cygwin doesn't install an SSH server by default, although you can set up sshd if you want. By default, however, there's nothing to ssh to.
Follow the steps in this link and then do a
$~ net start sshd
$~ ssh localhost