![](/img/trans.png)
[英]After running a bash script as root user, how can I have the script automatically force my user to exit root?
[英]can we write a simple bash script to automatically login as root user
我通常每天必須以超級用戶身份登錄20到50次,一次又一次鍵入長密碼。
我剛剛創建了一個簡單的bash腳本
#!/bin/bash
sudo -s
echo password
。/測試
輸出root @ localhost:密碼,當我執行它時,它的作用就像魅力...但是它在屏幕上顯示我的密碼.....
為這個小問題做一個其他最佳解決方案......
我希望這不是安全標准中的全部解決方案……在不公開密碼的情況下,我們還能有其他解決方案嗎?
您可以將回顯的密碼傳遞到命令中。 嘗試這樣的事情:
echo myPassword | sudo -S
您可以在這里看到更多信息。
問題是,您真的要在shell腳本文件中輸入密碼嗎? (只是強調這是一個可怕的想法)
只需將腳本所有權更改為root並在用戶中設置SUID位的權限
chmod u = rws g + x o + x script123
該腳本將以root身份為每個用戶運行
您可以將sudo
配置為僅每隔幾分鍾就要求輸入密碼。 默認值為5分鍾。 閱讀sudoers
手冊頁並向下滾動至:
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代替本教程中的以下內容,這是安全的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.