可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I am trying to set up a VPN with a Raspberry Pi, and the first step is gaining the ability to ssh
into the device from outside my local network. For whatever reason, this is proving to be impossible and I haven't the slightest clue why. When I try to ssh
into my server with user@hostname
, I get the error:
ssh: Could not resolve hostname [hostname]: nodename nor servname provided, or not known
However, I can log into the server with,
ssh user@[local IP]
The server is a Raspberry Pi Model B running the latest distribution of Raspbian and the machine I am trying to connect to it with is a Macbook Pro running Mavericks. ssh
was enabled on the Raspberry Pi when I set up Raspbian.
I have perused Stack Overflow for hours trying to see if anyone else had this problem and I have not found anything. Every ssh
tutorial I find says that I should just be able to set it up on the remote machine and log in from anywhere using a hostname, and I have never had success with that.
回答1:
Recently I came across the same issue. I was able to ssh to my pi on my network, but not from outside my home network.
I had already:
- installed and tested ssh on my home network.
- Set a static IP for my pi.
- Set up a Dynamic DNS service and installed the software on my pi.
I referenced these instructions for setting up the static ip, and there are many more instructional resources out there.
Also, I set up port forward on my router for hosting a web site and I had even port forward port 22 to my pi's static IP for ssh, but I left the field blank where you specify the application you are performing the port forwarding for on the router. Anyway, I added 'ssh' into this field and, VOILA! A working ssh connection from anywhere to my pi.
I'll write out my router's port forwarding settings.
(ApplicationTextField)_ssh (external port)_22 (Internal Port)_22 (Protocal)_Both (To IP Address)_192.168.1.### (Enabled)_checkBox
Port forwarding settings can be different for different routers though, so look up directions for your router.
Now, when I am outside of my home network I connect to my pi by typing:
ssh pi@[hostname]
Then I am able to input my password and connect.
回答2:
I had the same issue connecting to a remote machine. but I managed to login as below:
ssh -p 22 myName@hostname
or:
ssh -l myName -p 22 hostname
回答3:
If you're on Mac, restarting the DNS responder fixed the issue for me.
sudo killall -HUP mDNSResponder
回答4:
If you need access to your VPN from anywhere in the world you need to register a domain name and have it point to the public ip address of your VPN/network gateway. You could also use a Dynamic DNS service to connect a hostname to your public ip.
If you only need to ssh from your Mac to your Raspberry inside your local network, do this: On your Mac, edit /etc/hosts
. Assuming the Raspberry has hostname "berry" and ip "172.16.0.100", add one line:
# ip hostname
172.16.0.100 berry
Now: ssh user@berry
should work.
回答5:
I had the same issue, which I was able to resolve by adding a .local to the host name, ala ssh user@hostname.local
回答6:
I had the same problem: The address shown in Preferences -> Sharing -> Remote Login didn't work and I got a '... nodename nor servname provided, or not known'. However, when I manually edited the settings (in Preferences -> Sharing -> Remote Login -> edit) and enabled "Use dynamic global hostname", it suddenly worked.
![](https://www.manongdao.com/static/images/pcload.jpg)
![](https://www.manongdao.com/static/images/pcload.jpg)
回答7:
If your command is:
$ ssh -p 1122 path/to/pemfile user@[hostip/hostname]
You will also face the same error
ssh: Could not resolve hostname [hostname]: nodename nor servname provided, or not known
when you miss the option -i /path/to/pemfile
of ssh
So Command should be:
$ ssh -p 1122 -i path/to/pemfile user@[hostip/hostname]
回答8:
This was happening to me when trying to access Github. The problem is that I was in the habit of doing:
git remote add <xyz> ssh:\\git@github.com......
But, if you are having this error from the question, removing ssh:\\
may resolve the issue. It solved it for me!
Note that you will have to do a git remote remove <xyz>
and re-add the remote url without ssh:\\
.
回答9:
I needed to connect to remote Amazon server
ssh -i ~/.ssh/test.pem -fN -L 5555:localhost:5678 ubuntu@hostname.com
I was getting the following error.
ssh: Could not resolve hostname <hostname.com>: nodename nor servname provided, or not known
Solution For Mac OSX
Pinging the host resolved the issue. I am using Mac OSX Seirra.
ping hostname.com
Now problem resolved. Able to connect to the server.
Note: I tried this solution also. But it didn't work out. Then ping
resolved the issue.
回答10:
It seems that some apps won't read symlinked /etc/hosts
(on macOS at least), you need to hardlink it.
ln /path/to/hosts_file /etc/hosts
回答11:
Try this, considering your allowed ports. Store your .pem
file in your Documents
folder for instance.
To gain access to it now all you have to do is cd [directory]
, which moves you to the directory of the allotted file. You can first type ls
, to list the directory contents you are currently in:
ls
cd /Documents
chmod 400 mycertificate.pem
ssh -i "mycertificate.pem" ec2-user@ec2-1-2-3-4.us-compass-0.compute.amazonaws.com -p 80