如果您的Mac是您的主计算机,您会希望能够从另一台计算机远程连接到它(the ability to connect to it remotely from another computer)。即使您不在计算机旁,您也可以访问您的文件和文件夹。
如果您的第二台计算机恰好是Windows计算机,您可以使用SSH协议从您的Windows计算机远程连接到您的Mac 。这在您的两台计算机之间建立了一个非常安全的连接,并让您可以从Windows计算机处理您的(Windows)Mac文件。
为了通过SSH将(SSH)Windows PC 连接到您的Mac,您需要首先在您的Mac上配置一些选项。然后,您就可以从位于世界任何地方的任何Windows计算机连接到您的(Windows)Mac 。
在 Mac 上启用远程登录功能(Enable The Remote Login Feature On Mac)
您的Mac具有一项称为远程登录(Remote Login)的功能,它允许您网络上以及Internet上的其他计算机远程连接到您的Mac并在其上执行任务。为了能够从Windows PC SSH 到您的(Windows)Mac,您需要首先在您的Mac上启用此选项。
- 单击(Click)屏幕左上角的Apple标志,然后选择(Apple)System Preferences。
- 在以下屏幕上,找到显示“共享(Sharing)”的选项并单击它。它将打开Mac的共享设置菜单。
- 打开的屏幕有几个选项可让您共享Mac的内容。在列表中找到显示远程登录(Remote Login)的选项,并在其框中打勾。这将在您的Mac(Mac)上启用该功能。
您现在已准备好通过SSH从您的 Windows PC连接到您的Mac。
您现在唯一需要的是Mac的 IP 地址。如果您要从与Mac位于同一网络的Windows计算机进行连接,则需要(Windows)Mac的本地 IP 。然后,您无需在路由器上启用端口转发。
如果您要从不在家庭网络中的Windows计算机进行连接,则需要(Windows)Mac的全局 IP 。在这种情况下,您需要按照下面给出的端口转发说明远程访问您的Mac 。
查找 Mac 的本地 IP(Find The Local IP Of Your Mac)
您将在之前访问的“共享(Sharing)”窗格中找到 Mac 的本地 IP。如果您已经关闭它,请单击顶部的WiFi图标并选择(WiFi)Open Network Preferences。
您的 IP 地址应列在以下屏幕上。
查找 Mac 的全球 IP(Find The Global IP Of Your Mac)
您可以通过简单的Google搜索在全球(Google)Internet上找到您的 IP 地址。
前往谷歌并搜索我的 IP 地址(My IP Address)。
谷歌(Google)会让你知道你的公共 IP 地址。
在路由器上设置端口转发(Set Up Port Forwarding On Your Router)
如果您要从远离您家而不是本地网络的Windows PC 远程连接到您的(Windows)Mac ,您需要如下所示转发路由器上的端口。(Mac)
- 在浏览器中打开一个新选项卡,在地址栏中输入192.168.1.1 ,然后(192.168.1.1)按 Enter(Enter)。它将打开路由器的设置页面。
- 当页面打开时,使用默认登录名登录,即两个字段的admin和admin并继续。
- 单击顶部的转发以打开您的转发设置页面。(Forwarding)
- 在以下屏幕上单击端口转发。(Port Forwarding)在两个端口字段中输入22和22 。然后,在LAN IP字段中输入(LAN IP)Mac的本地 IP ,勾选Enable,然后单击底部的OK 。
您的 IP 在端口 22 上的所有传入流量现在都将转发到您的Mac。您使用端口 22 的原因是因为它是SSH用于连接的端口。
使用 PuTTY 通过 SSH 远程连接到 Mac(Remote Connect To Mac with SSH Using PuTTY)
PuTTY是一个免费的SSH客户端,可用于Windows机器,让您可以通过 SSH 协议轻松连接到任何远程计算机(connect to any remote computer over the SSH protocol)。这是您将用于从Windows计算机远程连接到Mac的工具。(Mac)
- 前往PuTTY网站并在您的 PC 上下载并安装该应用程序。
- 安装后启动应用程序。主界面显示了几个可以输入值的字段。
- 将光标放在Host Name字段中,然后输入(Host Name)Mac的 IP 地址。
- 确保端口(Port)字段中有22。
- 选择SSH选项以确保您使用SSH协议进行连接。
- 最后,单击打开以打开与(Open)Mac的远程连接。
- 它会要求您输入Mac的用户名。输入(Enter)您的Mac用户名,然后按Enter。
- 系统将要求您输入用户帐户密码。输入Mac 用户(Mac user)帐户密码,然后按Enter。
- 如果一切顺利,您将从 Windows PC 连接到您的Mac。
现在您已连接,您将想知道您可以使用SSH连接执行哪些操作。以下是您可以运行以在Mac上执行操作的(Mac)一些基本命令(some of the basic commands)。
查看文件和文件夹列表(View Files And Folders List)
要查看当前目录的文件和文件夹列表,可以运行以下命令。
ls
更改目录(Change The Directory)
要更改SSH会话中的当前目录,请使用以下命令。
cd 新目录(cd new-directory)
查看文件内容(View File Contents)
您可以使用SSH命令访问文件的内容,如下所示。
cat 文件名.ext(cat file-name.ext)
新建一个文件夹(Create a New Folder)
SSH也允许您创建新目录。为此,请运行以下命令。
mkdir 目录名(mkdir directory-name)
创建一个新文件(Create a New File)
您甚至可以通过Windows在(Windows)Mac上远程创建新文件。
触摸文件名.ext(touch file-name.ext)
删除文件(Delete a File)
要删除Mac上的文件,请在 PC 上使用以下命令。
rm 文件名.ext(rm file-name.ext)
除了这些之外,SSH还有其他几个命令,您可以使用这些命令从 PC在Mac上执行任务。(Mac)
How to Remote Connect to Mac from Windows with SSH
If your Mac is your primary computer, you’ll like to have the ability to connect to it remotely from another computer. This gives you access to your files and folders even when you’re away from your machine.
If your second computer happens to be a Windows machine, you can use the SSH protocol to remote connect to your Mac from your Windows computer. This establishes a very secure connection between two of your computers and lets you work on your Mac files from your Windows machine.
In order to connect a Windows PC to your Mac via SSH, you need to first configure a few options on your Mac. Then you’ll be all set to connect to your Mac from any Windows computer located anywhere in the world.
Enable The Remote Login Feature On Mac
Your Mac has a feature called Remote Login that allows other computers on your network as well as on the Internet to remote connect to your Mac and perform tasks on it. To be able to SSH into your Mac from a Windows PC, you need to first enable this option on your Mac.
- Click on the Apple logo at the top-left corner of your screen and select System Preferences.
- On the following screen, find the option that says Sharing and click on it. It’ll open the sharing settings menu for your Mac.
- The screen that opens has several options letting you share the contents of your Mac. Find the option that says Remote Login in the list and put a tick-mark in its box. This will enable the feature on your Mac.
You are now all set to connect to your Mac from your Windows PC over SSH.
The only thing you now need is the IP address of your Mac. If you’ll be connecting from a Windows machine that is on the same network as your Mac, you’ll need the local IP of your Mac. You then don’t need to enable port forwarding on your router.
If you’ll be connecting from a Windows machine that’s not on your home network, you’ll need the global IP of your Mac. In this case, you’ll need to follow the port forwarding instructions given below to access your Mac remotely.
Find The Local IP Of Your Mac
You’ll find your Mac’s local IP on the Sharing pane you accessed previously. If you’ve closed it already, click on the WiFi icon at the top and select Open Network Preferences.
Your IP address should be listed on the following screen.
Find The Global IP Of Your Mac
You can do a simple Google search to find your IP address on the global Internet.
Head over to Google and search for My IP Address.
Google will let you know your public IP address.
Set Up Port Forwarding On Your Router
If you’re going to be remotely connecting to your Mac from a Windows PC far away from your home and not on your local network, you’ll need to forward the port on your router as shown below.
- Open a new tab in your browser, enter 192.168.1.1 in the address bar, and hit Enter. It’ll open your router’s settings page.
- When the page opens, log in using the default login which is admin and admin for both the fields and continue.
- Click on Forwarding at the top to open your forwarding settings page.
- Click on Port Forwarding on the following screen. Enter 22 and 22 in both port fields. Then, enter the local IP of your Mac in the LAN IP field, tick-mark Enable, and click on OK at the bottom.
All the incoming traffic for your IP on port 22 will now be forwarded to your Mac. The reason you used port 22 is because it’s the port that SSH uses for connections.
Remote Connect To Mac with SSH Using PuTTY
PuTTY is a free SSH client available for Windows machines that lets you easily connect to any remote computer over the SSH protocol. This is what you’ll be using to remote connect to your Mac from your Windows computer.
- Head over to the PuTTY website and download and install the app on your PC.
- Launch the app when it’s installed. The main interface shows several fields you can enter values.
- Put your cursor in the Host Name field and type in the IP address of your Mac.
- Ensure the Port field has 22 in it.
- Select the SSH option to ensure you’re connecting using the SSH protocol.
- Finally, click on Open to open a remote connection to your Mac.
- It’ll ask you to enter the username for your Mac. Enter your Mac username and press Enter.
- You’ll be asked for your user account password. Enter the Mac user account password and press Enter.
- If all goes well, you’ll be connected to your Mac from your Windows PC.
Now that you’re connected, you’ll want to know what things you can do with your SSH connection. Here are some of the basic commands you can run to perform actions on your Mac.
View Files And Folders List
To view the files and folders list for your current directory, you can run the following command.
ls
Change The Directory
To change the current directory in your SSH session, use the following command.
cd new-directory
View File Contents
You can access the contents of a file using an SSH command as follows.
cat file-name.ext
Create a New Folder
SSH lets you create new directories as well. To do it, run the following.
mkdir directory-name
Create a New File
You can even create a new file remotely on your Mac from Windows.
touch file-name.ext
Delete a File
To get rid of a file on your Mac, use the following command on your PC.
rm file-name.ext
In addition to these, SSH has several other commands you can use to perform tasks on your Mac from your PC.