Mac下开启/关闭ftp

    Hurray 3976次浏览 0条评论 1042字

#Mac

## 背景 很久以前在Mac上开启了ftp服务。但几乎没用过。前几天扫描我的电脑开放端口的时候发现21端口居然一直开着,并且尝试了很多办法都没有找到哪个程序开着ftp服务(比如`ps aux`)。 ![](https://file.hurray0.com/uploads/menu/28/4399827ad010d44d77f426519d3e53a9.png) 今天闲下来仔细查了一下,才把它关掉。同理,Mac下是可以开启ftp服务器的,只是`sierra`(Mac OS 10.10)之后用户界面里面找不到了(大概是没人用了吧,现在用`smb协议`的比较多,操作方便,不用专门的客户端) 先说原理,操作可以翻到最后。 ## 原理 我在用`sudo lsof -i:21`命令的时候发现了ftp的踪迹。如图: ![](https://file.hurray0.com/uploads/menu/28/fdfc265149f653ea62d29689b6d53d87.png) Mac下使用`launchd`守护进程(PID1)来对最重要的程序进行管理。任何用户都没有权限直接操纵和kill掉该进程。只能用`launchctl`进行管理。 `launchd`主要功能是进程管理。可以理解成是一个常驻在后台的进程,根据用户的配置,来响应特定的系统事件。launchd既可以用于系统级别的服务,又可以用于个人用户级别的服务。 更详细的这里转载一篇,[http://www.makaidong.com/博客园知道/4476.shtml](http://www.makaidong.com/博客园知道/4476.shtml) ## 操作 参考资料:[https://gaborhargitai.hu/enable-built-in-ftp-server-in-mac-os-x-yosemite-el-capitan-sierra/]() To __turn on__ the FTP server, paste this into the command prompt: `sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist` To __turn off__ the FTP server, issue the following command: `sudo -s launchctl unload -w /System/Library/LaunchDaemons/ftp.plist` Now you can access your Mac via FTP using a command like this from another computer on the network: ``` ftp://user@your_mac_ip ftp://user@your_mac_hostname ```

最后修改: