先在树莓派上生成SSH Key:
- ssh-keygen -t rsa -C <YOURNANME>@<YOURDEVICE>
- cd ~
- install -d -m 700 ~/.ssh
- cat ~/.ssh/id_rsa.pub | ssh <USERNAME>@<IP-ADDRESS> 'cat >> .ssh/authorized_keys'
也可在putty或其它软件上生成
然后将生成的公钥 pi.pub 用Samba/SFTP/ZMODEM传送至树莓派
- cat pi.pub >> .ssh/authorized_keys
7.为SSH启用两步认证
- sudo apt-get install libpam-google-authenticator
配置:
- google-authenticator
截屏(WIN: WIN + Prtscr, Android: Power Button + Volume -) 存至安全的地方
所有选项均选yes
用手机扫描二维码
- sudo nano /etc/pam.d/sshd
添加:
- auth required pam_google_authenticator.so
然后
- sudo nano /etc/ssh/sshd_config
找到 ChallengeResponseAuthentication
把 no 改成 yes
- sudo apt-get install ssh
- sudo /etc/init.d/sshd restart
测试:
- ssh pi@raspberrypi