在日常使用過程中,當有時候需要運行開機自啟腳本,同時想看到輸出結果的時候,不免就需要將系統配置為免密登錄模式,本文主要介紹再init3模式(多用戶命令行界面),運行開機自啟腳本及輸出腳本指令運行數據結果。本文使用的系統主要為CentOS7以上、Redhat7以上版本。
配置開機免密登錄
-第一種免密登錄方式
#切換到gdm目錄下,找到custom.conf文件
[root@localhost ~]# cd /etc/gdm/
#改目錄下有很多文件,我們只需要找到custom.confg文件并使用vi打開
[root@localhost gdm]# ls
custom.confg Init PostLogin PreSession Xsession
#打印出來看一下該文件內容
[root@localhost gdm]# cat custom.confg
# GDM configuration storage
[daemon]
[security]
[xdmcp]
[chooser]
[debug]
#Uncomment the line below to turn on debugging
#Enable=true
[root@localhost gdm]# vi custom.confg
~
#找到[daemon],并添加如下內容保存
[daemon]
AutomaticLoginEnable=True
AutomaticLogin=root #自動登錄的用戶名
-第二種免密登錄方式,在本案例中不適用,再CentOS6版本中可行
#切換到getty.target.wants目錄,并找到getty@tty1.service
[root@localhost ~]# cd /etc/systemd/system/getty.target.wants
#該目錄下通常就一個文件
[root@localhost getty.target.wants]# ls
getty@tty1.service
[root@localhost getty.target.wants]# vi getty@tty1.service
~
#打開之后,尋找[Service]下的ExecStart行,并添加--autologin root后,保存
[Serxice]
# the VT is cleared by TTYVDisallocate
ExecStart=-/sbin/agetty --autologin root --noclear %I $TERM
.......
開機自啟腳本
-注:若是腳本無法運行可關閉Linux的防火墻
#打開selinux文件,并找到SELINUX行,修改后面內容,使之disabled
[root@localhost~]# vi /etc/config/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values;
# enforcing - SELinux security policy is enforced.
# permissice - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values;
# targeted - Targeted processes are protected.
# minimum - Modification of targeted policy.Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
-第一種方法
#再root目錄下,找到用戶配置文件.bash_profile
[root@localhost ~]# ls -a
. .bash_logout .......
.. .bash_profile ........
........
#打開該文件,并將光標移至文件末尾,添加自啟腳本路徑及名稱,并保存
[root@localhost ~]# vi .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
.~/.bashrc
fi
# User specific environment and startup programs
PATH=#PATH:$HOME/bin
export PATH
sh /root/filenane.sh
-第二種方法
#切換至 /etc/init.d 目錄下,并將腳本拷貝到該目錄
[root@localhost ~]# cd /etc/init.d/
[root@localhost init.d]# cp /root/filename.sh ../init.d/
[root@localhost init.d]# ls
functions netconsole network README rhnsd filename.sh
[root@localhost init.d]# vi filename.sh
~
#在腳本開頭,添加如下內容
> #chkconfig: 2345 80 90
> #description:filename.sh #filename.sh為當前腳本自身名稱
#在chkconfig工具服務列表中增加此服務
[root@localhost init.d]# chkconfig --add filename.sh
聲明:本人所寫的只是本人在使用中遇到的問題做個記錄總結,很多內容也是百度,或者查閱官方文檔,若與他人有重復;若需按照本文配置,請認真確認是否適合你的情況,造成一切損失;本人概不負責。