如何在 OS X 10.6.7中打开端口22

我试图在 osx 上打开端口22,这样我就可以使用 ssh 连接到 localhost。我现在的情况是:

ssh localhost
ssh: connect to host localhost port 22: Connection refused

我已经生成了一个密钥,并将其放入我的 Authored_ keys 文件,如下所示:

sh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

一个“网络实用程序”端口扫描确认22(令人惊讶的是23)是关闭的。

背景: 我正致力于在本地设置 Hadoop。在我的配置中,我在 localhost: # # # # s 上运行服务,需要通过 ssh 打开与它们的通信。

我如何打开22? 或者我可能遇到另一个问题(也许是不正确生成的密钥?)

160100 次浏览

I think your port is probably open, but you don't have anything that listens on it.

The Apple Mac OS X operating system has SSH installed by default but the SSH daemon is not enabled. This means you can’t login remotely or do remote copies until you enable it.

To enable it, go to ‘System Preferences’. Under ‘Internet & Networking’ there is a ‘Sharing’ icon. Run that. In the list that appears, check the ‘Remote Login’ option. In OS X Yosemite and up, there is no longer an 'Internet & Networking' menu; it was moved to Accounts. The Sharing menu now has its own icon on the main System Preferences menu. (thx @AstroCB)

This starts the SSH daemon immediately and you can remotely login using your username. The ‘Sharing’ window shows at the bottom the name and IP address to use. You can also find this out using ‘whoami’ and ‘ifconfig’ from the Terminal application.

These instructions are copied from Enable SSH in Mac OS X, but I wanted to make sure they won't go away and to provide quick access.

I couldn't solve the problem; Then I did the following and the issue was resolved: Refer here:

sudo launchctl unload -w /System/Library/LaunchDaemons/ssh.plist
(Supply your password when it is requested)
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist
ssh -v localhost
sudo launchctl list | grep "sshd"
46427   -   com.openssh.sshd

I'm using OSX 10.11.6 and this article works for me.

enter image description here

There are 3 solutions available for these.

1) Enable remote login using below command - sudo systemsetup -setremotelogin on

2) In Mac, go to System Preference -> Sharing -> enable Remote Login that's it. 100% working solution

3) Final and most important solution is - Check your private area network connection . Sometime remote login isn't allow inside the local area network.

Kindly try to connect your machine using personal network like mobile network, Hotspot etc.

As per macOS 10.14.5, below are the details:

Go to

system preferences > sharing > remote login.

If you try to enable remote login from a terminal window, you may get a "full disk permission issue". Alternatively, You can enable it from Apple Icon -> System Preferences -> Sharing

I am using Mac-bigSur and this is how I enable it on my machine

enter image description here

You can allow access to specific users also.