linux系统配置脚本,Linux系统配置脚本开机自启

在日常使用过程中,当有时候需要运行开机自启脚本,同时想看到输出结果的时候,不免就需要将系统配置为免密登录模式,本文主要介绍再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

声明:本人所写的只是本人在使用中遇到的问题做个记录总结,很多内容也是百度,或者查阅官方文档,若与他人有重复;若需按照本文配置,请认真确认是否适合你的情况,造成一切损失;本人概不负责。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值