免密码远程登陆iOS设备

前提条件

  1. 越狱设备
  2. 设备已安装OpenSSH

流程

  1. 生成RSA证书
  2. 推送公钥到iOS设备
  3. 配置~/.ssh/config文件
  4. 远程SSH登陆

生成RSA证书

ssh-keygen

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$ ssh-keygen

// 默认为id_rsa 可另取名比如 iPadMini 密码Apple$%^321
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/Jason/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in iPadMini.
Your public key has been saved in iPadMini.pub.
The key fingerprint is:
SHA256:6lL+mpTksDTg4CsPiqD1WIemisd1BeoLtbXmgKuhjto Jason@BJ-iAir
The key's randomart image is:
+---[RSA 2048]----+
| |
| . |
|. . . . |
|.o .o . . |
| ..++o.oS |
| +.=B=o |
|=o.+=O* |
|X*+*o+o. |
|&=E ..+o. |
+----[SHA256]-----+

将RSA证书移动到~/.ssh/目录下

1
2
$ mv iPadMini ~/.ssh/
$ mv iPadMini.pub ~/.ssh/

推送公钥到iOS设备

~/.ssh/ 目录是否存在

1
2
3
4
5
$ ssh root@your_device_ip

// 没有.ssh目录时
$ cd ~
$ mkdir .ssh

推送公钥

1
2
3
4
$ scp ~/.ssh/iPadMini.pub root@your_device_ip:/var/root/.ssh/

root@192.168.5.105's password:
iPadMini.pub 100% 395 0.4KB/s 00:00

修改公钥文件名

1
2
3
4
$ cd ~/.ssh/
// 当不存在authorized_keys该文件时 可以
$ mv iPadMini.pub authorized_keys
// 当存在时,可用cat将公钥加到authorized_keys文件尾

配置~/.ssh/config文件

1
2
3
4
5
// 进行远程登陆操作的计算机(比如 Mac OS)
$ cd ~/.ssh/

// 查看config文件是否存在,不存在则创建
$ mkdir config

config内容格式:

1
2
3
4
5
Host aMini
HostName your_device_ip ## 设备ip
User root ## 用户名
PreferredAuthentications publickey
IdentityFile ~/.ssh/iPadMini ## 指定RSA私钥文件

远程登陆

1
2
3
$ ssh aMini
Enter passphrase for key '/Users/Jason/.ssh/iPadMini':
niya:~ root#

已经能免密码SSH登陆了

理解objc运行时一:类是什么 iOS远程推送总结
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×