如何解决普通用户使用 sudo 找不到命令
转载自:http://t.zoukankan.com/murry-p-8717151.html
====================================
一、在linux的普通用户下,要使用root权限的命令需要使用sudo
[dev@dev1 client_api]# sudo git pull origin develop sudo: git: command not found
但是发现git命令找不到
二、使用whereis找git的绝对路径
[dev@dev1 client_api]$ whereis git git: /usr/local/git
再次尝试
[dev@dev1 client_api]$ sudo /usr/local/git pull origin develop sudo: /usr/local/git: command not found
还是不对的 换成which试试
[dev@dev1 client_api]$ which git /usr/local/git/bin/git
这次找到的位置是截然不同的
再次尝试
[dev@dev1 client_api]$ sudo /usr/local/git/bin/git pull origin develop From IP地址:client_api * branch develop -> FETCH_HEAD Updating 81608e5..815cbbb error: Your local changes to the following files would be overwritten by merge: app/Models/OrderMaster.php app/Services/OrderService.php config/params.php Please, commit your changes or stash them before you can merge. Aborting
很明显成功了
三、寻找原因
因为sudo默认的配置文件下只是指定三个命令位置,如下
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
所以采用软连接的方式
ln -s /usr/local/git/bin/git /usr/bin/git
这次再尝试直接使用命令
[dev@dev1 client_api]$ sudo git pull origin develop remote: Counting objects: 34, done. remote: Compressing objects: 100% (21/21), done. remote: Total 21 (delta 13), reused 0 (delta 0) Unpacking objects: 100% (21/21), done. From IP地址:018_client_api * branch develop -> FETCH_HEAD 815cbbb..a93dc24 develop -> origin/develop Updating 81608e5..a93dc24 error: Your local changes to the following files would be overwritten by merge: app/Models/OrderMaster.php app/Services/OrderService.php config/params.php routes/api.php Please, commit your changes or stash them before you can merge. Aborting
好了 完美
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示