简体   繁体   中英

can we write a simple bash script to automatically login as root user

I usually have to login in 20 to 50 times daily as a super user, typing the long password again and again..

i have just created a simple bash script

#!/bin/bash

sudo -s
echo password

./test

output root@localhost: password when i execute it, it works like charm... but it shows my password on the screen.....

do some one have any other best solution...... for this small problem.......

i hope this is not all the solution in security standard...... can we have any other solution with out exposing my password.....

You can pipe the echo'd password into a command. Try something like this:

echo myPassword | sudo -S 

You can see come more info on this here .

Question is, do you REALLY want your password in a shell script file? (just emphasizing that its a terrible idea)

just change ownership of the script to root & set SUID-Bit in user the permissions

chmod u=rws g+x o+x script123

the script will run as root for every user

You can configure sudo to require a password only every so many minutes. The default is 5 minutes. Read the sudoers man page and scroll down to this:

    timestamp_timeout
               Number of minutes that can elapse before sudo will ask
               for a passwd again.  The timeout may include a
               fractional component if minute granularity is
               insufficient, for example 2.5.  The default is 5.  Set
               this to 0 to always prompt for a password.  If set to a
               value less than 0 the user's timestamp will never
               expire.  This can be used to allow users to create or
               delete their own timestamps via sudo -v and sudo -k
               respectively.

您是否有理由不能sudo su -成为root用户,而不是在所有命令前加上sudo blah

一个简单的解决方案是使用密钥库身份验证,请使用ssh-copy-id代替本教程中的以下内容,这是安全的

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM