SSH Connection from MAC to Amazon EC2 not working - macos

I am trying to connect to Amazon EC2 via:
ssh -i ~/.ssh/YOUR_KEYPAIR_FILE.pem ec2-user#YOUR_IP_ADDRESS
The terminal takes 1 or 2 mins and then prints:
ssh: connect to host XXX port 22: Operation timed out
Any ideas?

Login to AWS
Go to the Instances section
Click on the security group associated with your EC2 instance
Down the bottom click on the inbound tab and then click edit
Create this rule
TYPE SSH
PROTOCOL TCP
PORT RANGE 22
SOURCE Anywhere
You should now be able to connect to the instance on port 22 via ssh with your key.

You need to open port 22 in your security group. All ports are closed by default.

Can you try changing permissions to YOUR_KEYPAIR_FILE.pem like this
chmod 600 YOUR_KEYPAIR_FILE.pem
Then shoot the command
ssh -i YOUR_KEYPAIR_FILE.pem ec2-user#YOUR_IP_ADDRESS

I had a similar problem. I checked all my networking time and time again from the ec2 instance all the way through the VPC and out to the internet. Security groups were allowing all sources through ports 22 and 80. My NACL was allowing the right permissions. I knew AWS was all ok yet everytime I went to try ssh into an instance I would still get an operation timeout, indicating that problem must be with my local machine instead.
First to check that the ssh port was open I ran the following:
ssh localhost
This worked fine!
Afte doing some research on the net, in the end it all boiled down to java and my terminal not recognising that java was installed on my machine.
Supporting Document:
AWS Documentation
No Java means that your .pem will not be recognised
Start by running the follwing:
java -version
If you get no hits then install relevant java SDK for your OS and once installed run
which java
You should get something like this:
/usr/bin/java
Now we can try connect to an instance again and hopefully you should have success this time!
ssh -v -i ~/Downloads/labamikey.pem ec2-user#ec2-34-200-217-2.compute-
__| __|_ )
_| ( / Amazon Linux AMI
___|\___|___|
[ec2-user#ip-10-0-0-54 ~]$

Related

Could not connect VM on port 22 in Google cloud

I have installed hadoop (HDP ) in the google cloud vm instance , after sometime when i tried to connect the machine again, it is showing error :
"We are unable to connect to VM on port 22" .
To get additional debug logs try to SSH using verbose flag using the following command:
$ gcloud compute ssh INSTANCE_NAME --zone ZONE --ssh-flag="-vvv"
If the above step doesn’t help, connect to the instance using the serial console of the affected instance and check if this issue has to do with open port as Abhinav mentioned.
You find additional SSH troubleshooting information in the Help Center Article.

Can not SSH to Raspberry Pi 3 from Putty

I am not able to SSH to Raspberry Pi 3 from Putty. I can ping the 192.168.137.1 IP address assigned by sharing Internet connection.
The problem I realized that SSH is not enabled by default in Pi3 and saw the posts which suggest to enable SSH by creating 'ssh' file inside /boot folder. I got the SD card which has pre-installed Noobs so when I open SD card it shows only /recovery folder. How to enable SSH in this case ? Please help to resolve it .
Enable SSH like:
documentation
Or start it manually sudo service ssh start - note that manual option will require startup scrip to run at each startup.
Additional settings like port configuration should be done insshd_config. Do it with your favorite editor sudo nano /etc/ssh/sshd_config. Anyway your post should be opened at raspberry forum not at SO...
you can take a look at this thread
How can I get connection with Raspberry without access of its shell?
it mentions about PiBakery which will install rasbian with ssh support. by default ssh is disabled but this might help.

rsub with sublime and ssh connection refusual

I am trying to use rsub to create tunnel in ssh to sublime text, I run the command rmate .profile but i get the following response. I am using wateroof to open the ports 52968 on 1p4 and ip6, I followed the insturctions here and its just not working
I am running osx on my local machine and ubuntu 12.04 on my remote machine I am ssh into on digitalocean
root#anderskitson:~# rmate .profile
/usr/local/bin/rmate: connect: Connection refused
/usr/local/bin/rmate: line 186: /dev/tcp/localhost/52698: Connection refused
Unable to connect to TextMate on localhost:52698
I was having the same problem.
Let remoteHost = the IP or hostname of the machine you're attempting to ssh to.
I ran ssh -R 52698:localhost:52698 remoteHost from my local machine, after whice rmate .profile on remoteHost worked.
That led me to determine that ~/.ssh/config on my local machine was incorrect.
I set ~/.ssh/config to look like this:
Host remoteHost
RemoteForward 52698 localhost:52698
It's been working solidly since I made that change.
For anyone getting this same error using PuTTy on Windows, this commenter gives great instructions:
In PuTTy's config window, nagivate to the Connection > SSH > Tunnels pane
In the "Source Port" field, type 52698
In the "Destination" field, type 127.0.0.1:52698
Select the "Remote" and "Auto" radio buttons
Click the "Add" button
Go to the Session pane and save if you want to preserve these settings.
Here's an image which does the explaining visually:
I had the same issue and here is what works for me. If you have multiple servers you want this to work for, do the following as exactly shown here:
Host *
RemoteForward 52698 localhost:52698
I consulted this link: configure SSH config file and realized you can use * in config file.
Wildcards are also available to allow for options that should have a
broader scope.
I was trying to set this up for the first time using VS Code and got the generic "Connection refused" error even though my configuration seemed fine. It turned out to be because I hadn't reloaded the IDE after installing the rmate extension (Remote VSCode). Make sure that the rmate server is active on your local machine, whatever IDE you're using.
I had the same problem and fixed with replacing the HOSTNAME with the actual IP-Address when connecting:
e.g.: ssh pi#raspberrypi.local to ssh pi#192.168.1.1
I had the same problem and gone through most of the blogs, I did everything that was told.
At last, I found myself that textmate or submile editors are closed(force quit), this caused the problem.
For example my SSH config ~/.ssh/config file to connect with DigitalOcean with Remote Forward looks like:
Host DigitalOcean
Hostname xxx.xxx.xxx.xxx
User username
RemoteForward 52698 localhost:52698
and is called in a terminal
ssh DigitalOcean
rmate then connects fine with my local Atom editor
rmate stopped working for no apparent reason. Turns out I had tripped the 'man in the middle' check. I saw this warning when doing ssh --
\###########################################################
# WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! #
###########################################################
In my case, this warning was expected so I ignored it. This may not apply for you, so verify host identity. Didn't realize this line at the end of the warning --
Port forwarding is disabled to avoid man-in-the-middle attacks.
No wonder rmate stopped working. Verifying host identity and then clearing out offending entry from ~/.ssh/known_hosts made the warning go away and rmate started working again.
I run into this issue occasionally, and at least for my setup (which might be quite particular), I have found that killing zombie instances of ssh sessions does the job.
My particular setup :
I run Linux through a VM (VMWare Fusion) on my OSX host. Then I ssh into the the Linux host from OSX, and launch sublime from the Linux side. I usually have several ssh sessions running.
I recently rebooted my Mac (without first shutting down the VM, which was probably bad), and once I got back into the VM, was unable to launch Sublime - got the "connection refused" error mentioned by the OP.
So I did a ps aux on the Linux side, and looked for all instances of :
root 657399 0.0 0.1 13956 9332 ? Ss 14:52 0:00 sshd: user [priv]
user 657461 0.0 0.0 14088 5420 ? S 14:52 0:00 sshd: user#pts/1
(where user is my username). I killed the user jobs, e.g. 657461 above, and Voila! Every thing works now. Of course, in the process of killing these jobs, you are likely to kill the ssh session you are currently in, so you will have to log back into your session.
This might not work for users who don't have the necessary kill privileges on their remote machine, so don't know how useful this is, but thought I would put it out there.

Help Accessing Amazon EC2 Instance

Trying to set up first EC2 instance for simple (currently) php app, using osx 10.6. When i try to access my new instance in the command line i can only get ssh: connect to host xx.xxx.xxx.xxx port 22: Operation timed out.
i'm typing this at command line:
ssh -i <MYPEMNAME>.pem ec2-user#<PRIVATEIP/PUBLICDNS/ELASTICIP>
i have this as a security rule in the management console:
rule name: web_access
22(SSH) 0.0.0.0
80(HTTP) 0.0.0.0
i have ssh completely open just to test this, i'll get a more appropriate ip when it works.
i created an elastic IP, which was one option i tried after 'ec2-user#...'
i also generated a .pem when i created the instance which i have saved to a folder .ec2 on my machine, named as referenced in .pem above.
the management console says the instance is running. i think im just doing the ssh access wrong at this point.
any help tremendously appreciated!
thanks
Yeah, comments were pretty correct. It was an ssh issue and the main thing was that i was trying to add a custom security rule that allowed ssh but the default didn't. and for whatever reason the custom rule wasn't being applied so i just edited the default rule to allow port 22 (ssh) and I was pretty much up and running. Also needed to run chmod. !! Anddd, if you add a new keypair like I did, you may need to go into the ssh/known_hosts file and delete reference to your old keypair. that was hanging me up for a while with a an error out a middleman attack.
thanks

How to Connect to localhost with SSH(PuTTy)

I just figured how to connect to my webhost with PuTTy .
But how to I connect to my localhost? I put
Servername: localhost
port: 22 (I've tried 80 too)
And it gives me an error "failed to connect"
How do I connect?
If you are using Cygwin on your local host, you can connect to Cygwin's sshd (SSH Daemon).
3 easy commands to install the sshd as a service: (always there when you startup the machine)
$ ssh-host-config -y # enable sshd. "-y" answers yes to all queries.
$ cygrunsrv --start sshd # start it as an autostart Windows service
$ ssh localhost # try to recursively log in via ssh
Taken from: http://nfnaaron.posterous.com/tag/puttycyg#Section2
(The second approach)
=> You get the entire ssh infrastructure: public key authentication, ssh-agent, etc...
Ensure that you have running a SSH server (such as openssh-server) running on localhost and not just a web server (such as apache). Also ensure, that localhost is really mapping to 127.0.0.0/8
The solution in the answer above won't work unless you have installed Cygwin with the OpenSSH package selected - you have to do this manually during the installation process (see option a below).
Depending on the intended purpose of your connection you can try one of the options below, option (b) being much easier to install but lacking the *nix shell capabilities.
a. You can install a Cygwin shell with ssh server, this site (http://ist.uwaterloo.ca/~kscully/CygwinSSHD_W2K3.html) has instructions for Windows Server but they work for other Windows too with may be some of the questions shown in the output on the page not appearing on non-server version of Windows. Also, where it says in the instructions to issue the command:
mount -s --change-cygdrive-prefix /
delete the -s option so that the command is
mount --change-cygdrive-prefix /
(at least this was the case for me on Windows 7).
b. PuTTy site suggests WinSSHD (http://www.bitvise.com/winsshd-download). It's an easy self-installer. Once it's up you have to click onthe StartSSHD link about 1/3rd of the screen down on the first page of the config window. Then you can connect your PuTTy to localhost. However, in my experience, it didn't provide any *nix command support, only the native Windows ones and I couldn't find anything in their user guide on this.
Hope this helps.
Just adding this answer in case anyone is still looking for a solution.
In your hostname (or IP address) section, enter localhost or 127.0.0.1
Leave the port to its default value 22
Click on open
Now a login shell will popup -
Log in as your username, your username is basically what you get when you type whoami in your Terminal.
In the password section, type the password that you use as your system's password.
The above steps should connect localhost with ssh(PuTTY)

Resources