mac下开启ssh远程登录

老规矩,先说下ssh是什么,其缩写是secure shell,百度百科上如是描述:

SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Network Working Group)所制定;SSH 为建立在应用层基础上的安全协议。SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议。利用 SSH 协议可以有效防止远程管理过程中的信息泄露问题。SSH最初是UNIX系统上的一个程序,后来又迅速扩展到其他操作平台。SSH在正确使用时可弥补网络中的漏洞。SSH客户端适用于多种平台。几乎所有UNIX平台—包括HP-UX、Linux、AIX、Solaris、Digital UNIX、Irix,以及其他平台,都可运行SSH。

我们可以通过本机登录到远程服务器上进行操作,而本文要讲的则是如何在mac上开启ssh服务,以便用别人的机器可以登录到我们的mac上进行操作;
首先,在系统偏好设置中打开共享,勾选远程登录;
然后,打开本机的终端,输入:

ssh-keygen -t rsa

一直回车键就行,提示如下则生成秘钥成功:

Your identification has been saved in /home/vagrant/.ssh/id_rsa.
Your public key has been saved in /home/vagrant/.ssh/id_rsa.pub.
The key fingerprint is:
97:e9:5a:5e:91:52:30:63:9e:34:1a:6f:24:64:75:af root@cuican.local
The key's randomart image is:
+--[ RSA 2048]----+
|       .=.X .    |
|       . X B .   |
|        . = . .  |
|         . + o   |
|        S = E    |
|         o . .   |
|          o .    |
|         + .     |
|        . .      |
+-----------------+

接下来修改ssh配置文件:sudo vim /etc/ssh/sshd_config,修改配置如下:

Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::


# The default requires explicit activation of protocol 1
Protocol 2


# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /home/vagrant/.ssh/id_rsa


# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 1h
ServerKeyBits 1024


# Logging
# obsoletes QuietMode and FascistLogging
SyslogFacility AUTHPRIV
#LogLevel INFO


# Authentication:


LoginGraceTime 2m
PermitRootLogin yes
StrictModes yes
#MaxAuthTries 6
#MaxSessions 10


RSAAuthentication yes
PubkeyAuthentication yes

找到sshd的安装目录:

which sshd

一般mac的安装目录位于/usr/sbin/sshd,输入:

 /usr/sbin/sshd

即可启用sshd服务,这时,用另一台mac电脑打开终端,输入ssh命令即可登录

Leave a Reply

Your email address will not be published. Required fields are marked *