[root@guanz etc]# vi /etc/sudoers
[root@guanz etc]#
# 添加如下內(nèi)容:
guanz ALL=(ALL) ALL
示例:
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
guanz ALL=(ALL) ALL
## Allows members of the 'sys' group to run networking, software,
2、切換至普通用戶guanz,并測試命令:
2.1 方式一:【echo 'passwd' | sudo -S java -jar ****】
[root@guanz etc]# su guanz
[guanz@guanz etc]$
# 進(jìn)入jar包所在目錄下:
[guanz@guanz dell]$ cd app/
[guanz@guanz app]$ ll
total 599948
-rw-rw-r--. 1 guanz guanz 59162 Jul 1 11:09 log-210701-01.txt
-rwxrwxr-x. 1 guanz guanz 307142072 Jul 1 14:36 test-1.0.jar
# 查看當(dāng)前在運行的窗口程序
[guanz@guanz app]$ screen -ls
No Sockets found in /var/run/screen/S-guanz.
# 創(chuàng)建窗口腺律,并進(jìn)入,直接執(zhí)行java -jar啟動宜肉,會提示你輸入密碼:
[guanz@guanz app]$ screen -S jar
[guanz@guanz app]$ sudo java -jar test-1.0.jar > log-01.txt
[sudo] password for guanz:
# 通過【echo 'passwd' | sudo -S java -jar ****】再次執(zhí)行匀钧,會直接啟動,無需再輸入密碼谬返。
[guanz@guanz app]$ echo '123456' | sudo -S java -jar test-1.0.jar > log-01.txt
[sudo] password for guanz:
# 查看當(dāng)前在運行的窗口
[guanz@guanz app]$ screen -ls
There is a screen on:
17362.jar (Detached)
1 Socket in /var/run/screen/S-guanz.
[guanz@guanz app]$
# 查看日志文件之斯,發(fā)現(xiàn)文件已啟動:
2021-07-01 15:01:02.531 INFO 17548 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8890 (http) with context path ''
2021-07-01 15:01:02.534 INFO 17548 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 29.065 seconds (JVM running for 30.46)
至此,此命令有效遣铝。