gluttony
2013-09-02 23:24:27 +08:00
1. 外币信用卡申请一个AWS Free Tier。
2. 客户端Macbook Pro,AWS,Pi间创建SSH公私钥实现免密码登录。
3. Pi上.ssh目录里的config文件
Host *
AddressFamily inet
Compression yes
CompressionLevel 9
ServerAliveInterval 30
Host box
User nil
Hostname xx.xx.xx.xx
IdentityFile ~/.ssh/id_rsa
4. Pi上创建reverse_ssh_tunnel,并chmod +x reverse_ssh_tunnel
#!/bin/sh
# This is the username on your Pi who has public key authentication setup at the middleman
USER_TO_SSH_IN_AS=pi
# This is the username and hostname/IP address for the middleman (username on AWS)
MIDDLEMAN_SERVER_AND_USERNAME=nil
# Port that the middleman will listen on (use this value as the -p argument when sshing)
PORT_MIDDLEMAN_WILL_LISTEN_ON=10888
# Connection monitoring port
AUTOSSH_PORT=20888
su -c "autossh -M${AUTOSSH_PORT} -f -q -N -R '*:${PORT_MIDDLEMAN_WILL_LISTEN_ON}:localhost:22' ${MIDDLEMAN_SERVER_AND_USERNAME} -oLogLevel=error -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no" ${USER_TO_SSH_IN_AS}
我把reverse_ssh_tunnel放在了/etc/network/if-up.d/目录下,这样网络接通时会自动执行该脚本里的autossh。
5. AWS上.ssh目录里的config文件
Host *
AddressFamily inet
Compression yes
CompressionLevel 9
ServerAliveInterval 30
Host pi
User pi
Hostname 127.0.0.1
Port 10888
IdentityFile ~/.ssh/id_dsa
6. 客户端Macbook Pro上先 ssh aws 连接到AWS服务器上,再 ssh pi 就可以反向连接到Raspberry Pi上了。嫌麻烦可以再配一下自动连接aws中间跳板。