25、腳本要以root權限運行。

劃詞搜索,腳本要以root權限運行。

1、http://bbs.csdn.net/topics/390413278 Ubuntu 10.04 腳本在執行時需要權限怎麼辦?

chmod 6777 <fileName>  //前面的777前面的6就是設置suid、guid

    無效
    關於chmod和ls -l:
         chmod 777 修改權限 http://www.cnblogs.com/sipher/articles/2429772.html
         linux ls -l 詳解[轉] http://hi.baidu.com/sfzhaoif/item/3e2653c9426f28d497445220

2、http://forum.ubuntu.org.cn/viewtopic.php?f=21&t=396487&sid=ed6316242e5cc252c26e2f6396738b0d 怎樣讓shell腳本默認以root權限運行??

suid只對bin有效,當然,echo password |sudo -S也是一個不錯的建議。 

      我以爲bin是/bin目錄,後面才知道應該是二進制文件。
      把密碼明文寫在腳本里,太不專業了。。

3、http://forum.ubuntu.org.cn/viewtopic.php?f=21&t=105799 在shell腳本中如何使用超權限的命令
       中文沒搜到多少,大概就是這些方法
 
4、google:ubuntu script root permission的第一個鏈接就解決問題:
http://serverfault.com/questions/75620/ubuntu-let-a-user-run-a-script-with-root-permissions
內容見下,老外說得很清楚,很詳細。採用了ALL ALL=NOPASSWD: /path/to/script的方法,
這個方法在前面的鏈接中也有,只是說得太簡單,沒看懂什麼意思。

還是老外靠譜。。。。

劃詞搜索成功,但是反應太慢。。。。。。


If this was a normal binary, you could setuid by running

# chmod u+s /path/to/binary

Unfortunately, scripts can't be setuid. (Well you can, but it's ignored). The reason for this is that the first line of the script tells the OS what interpreter to run the script under. For example if you had a script with:

#!/bin/bash

You'd actually end up running

/bin/bash /path/to/script

Obviously, you'd need the interpreter to be setuid, which would then mean all scripts would be setuid. This would be bad.

You can do this with sudo by putting the following in your /etc/sudoers file by running visudo.

ALL ALL=NOPASSWD: /path/to/script

And now any user can run

$ sudo /path/to/script

This allows them to run the script without typing in their password.

There is an alternative that doesn't require sudo in the command, which requires creating a small setuided binary that execs your script, but every additional setuid binary adds another potential security problem.



從12年體驗12.04 之後放棄,到今年體驗14.04,(一轉眼兩年了,感慨下時光飛逝。。)感覺很糟。。。
Linux的自由開源,我現在沒什麼感覺。。。
說Linux穩定,我的感覺是比win7死機還頻繁,還會出現長按電源鍵都不反應,要拔電池的情況。。。
說Linux高效,現在基本還在配置系統的狀態,一堆細碎問題讓我蛋碎神傷。。。
重新熟悉各種常用軟件更是讓人望而卻步。。。。
還是先去學學ps、flash的比較實用。。。。。。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章