Linux sudo xxxx:command not found問題

在/usr/local/目錄下安裝了nginx,並將nginx/sbin加入PATH,卻提示:command not found。

# 切換到root用戶
$ vim /etc/profile  
export PATH=$PATH:/usr/local/nginx/sbin  
$ source /etc/profile  
$ which nginx
/usr/local/nginx/sbin/nginx
$ nginx -t #到這裏是OK的

#切換到普通用戶,比如test用戶
$ nginx -t
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/nginx/conf/nginx.conf:2
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: [emerg] open() "/vdb/logs/nginx/nginx.pid" failed (13: Permission denied)
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
#從輸出來看,這是權限不夠原因。

$ sudo nginx -t
sudo nginx:commmand not found
#加上sudo又提示找不到此命令
#明明把nginx加入了PATH環境變量,爲啥使用sudo,還找不到nginx這個命令了呢?

#經過一番苦苦思考與百度,發現只有在“/etc/sudoers”裏面的secure_path指定目錄下的命令纔可以使用sudo。
$ cat /etc/sudoers
......
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin
......

#解決方法:把nginx連接到/usr/bin下
$ ln -s /usr/local/nginx/sbin/nginx /usr/bin
$ sudo nginx -t 
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

 

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