配置Raspberry Pi上Raspbian系统为自动以root帐户登录

解锁raspibian系统的root帐号

正常情况下,Raspbian系统默认并没有开启root帐户,首先需要开启root帐户。先使用pi帐户登录系统(默认密码是:raspberry),然后执行下面的命令:

localhost:~ king$ ssh pi@192.168.0.110
pi@192.168.0.110's password: 

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Jul 28 16:04:49 2016 from 192.168.0.109
pi@raspberrypi:~ $ sudo passwd root
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
pi@raspberrypi:~ $ sudo passwd --unlock root
passwd: password expiry information changed.
pi@raspberrypi:~ $ su root
Password: 
root@raspberrypi:/home/pi# vi /etc/systemd/system/getty.target.wants/getty\@tty1.service 

查看系统启动相关配置文件

打开系统登录配置文件,内容如下:

   #  This file is part of systemd.
   #
   #  systemd is free software; you can redistribute it and/or modify it
   #  under the terms of the GNU Lesser General Public License as published by
   #  the Free Software Foundation; either version 2.1 of the License, or
   #  (at your option) any later version.

   [Unit]
   Description=Getty on %I
  Documentation=man:agetty(8) man:systemd-getty-generator(8)
  Documentation=http://0pointer.de/blog/projects/serial-console.html
  After=systemd-user-sessions.service plymouth-quit-wait.service
  After=rc-local.service

  # If additional gettys are spawned during boot then we should make
  # sure that this is synchronized before getty.target, even though
  # getty.target didn't actually pull it in.
  Before=getty.target
  IgnoreOnIsolate=yes

  # On systems without virtual consoles, don't start any getty. Note
  # that serial gettys are covered by serial-getty@.service, not this
  # unit.
  ConditionPathExists=/dev/tty0

  [Service]
  # the VT is cleared by TTYVTDisallocate
  ExecStart=-/sbin/agetty --noclear %I $TERM
  Type=idle
  Restart=always
  RestartSec=0
  UtmpIdentifier=%I
  TTYPath=/dev/%I
  TTYReset=yes
  TTYVHangup=yes 36 TTYVTDisallocate=yes
  KillMode=process
  IgnoreSIGPIPE=no
  SendSIGHUP=yes

  # Unset locale for the console getty since the console has problems
  # displaying some internationalized messages.
  Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPH    ONE= LC_MEASUREMENT= LC_IDENTIFICATION=

  [Install]
  WantedBy=getty.target
  DefaultInstance=tty1

修改系统配置文件

我们只要把第28 行从:

 ExecStart=-/sbin/agetty --noclear %I $TERM

改为:

 ExecStart=-/sbin/agetty --autologin root --noclear %I $TERM

保存后,重启就可以自动以root用户登录了。

后记

在比较后的raspbian系统中,SysV系统中使用/etc/inittab文件来管理相关配置,所以在网上查的资料大部分是关于这个文件设置的,较新的系统一般使用了systemd来管理相关配置,所以配置文件已经变以了博文中所修改的那个文件了。-_-#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值