树莓派安装SSH

1. 安装ssh

 sudo apt-get install openssh-server 

2. 检查树莓派SSH服务是否开启

 ps -e|grep ssh 

3. SSH服务开启

 sudo /etc/init.d/ssh start 

4. 在树莓派终端输入(临时的,重启失效):

sudo service ssh start
sudo service ssh status

如果ssh运行会打印如下类似信息:

ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-06-17 17:17:04 CST; 20h ago
  Process: 403 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
 Main PID: 439 (sshd)
   CGroup: /system.slice/ssh.service
           └─439 /usr/sbin/sshd -D

Jun 18 13:37:50 raspberrypi sshd[21733]: Accepted password for pi from 192.168.169.151 port 2805 ssh2
Jun 18 13:37:50 raspberrypi sshd[21733]: pam_unix(sshd:session): session opened for user pi by (uid=0)
Jun 18 14:09:45 raspberrypi sshd[30043]: Accepted password for pi from 192.168.169.151 port 10399 ssh2
Jun 18 14:09:45 raspberrypi sshd[30043]: pam_unix(sshd:session): session opened for user pi by (uid=0)
Jun 18 14:13:16 raspberrypi sshd[31028]: Accepted password for pi from 192.168.169.203 port 52093 ssh2
Jun 18 14:13:16 raspberrypi sshd[31028]: pam_unix(sshd:session): session opened for user pi by (uid=0)
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

5. 树莓派SSH服务开机自动启动

在终端命令行中启动SSH服务后,如果系统重启或关机后启动,SSH服务默认是关闭的,依然需要手动启动,为了方便可以设置SSH服务开机自动启动,打开 /etc/rc.local 文件,在语句 exit 0 之前加入:

 /etc/init.d/ssh start 

6.其他方式开启SSH

  1. 通过 sudo raspi-config 通过可视化界面开启SSH.
  2. 在SD开根目录创建SSH文件,开启SSH.
posted @ 2019-06-27 11:29  CoderZZZ  阅读(3492)  评论(0编辑  收藏  举报