手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Ubuntu中root用户没有办法使用命令

[日期:2009-10-12] 来源:purpleroom.blog.sohu.com  作者:purpleroom [字体:大 中 小]

lin@lenovo:~$ su - root
口令:
Command 'mesg' is available in '/usr/bin/mesg'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
-su: mesg:找不到命令
root@lenovo:~# gedit /etc/profile
Command 'gedit' is available in '/usr/bin/gedit'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
-su: gedit:找不到命令
root@lenovo:~# useradd yul
Command 'useradd' is available in '/usr/sbin/useradd'
The command could not be located because '/usr/sbin' is not included in the PATH environment variable.
This is most likely caused by the lack of administrative priviledges associated with your user account.
-su: useradd:找不到命令
root@lenovo:~# vi
Command 'vi' is available in '/usr/bin/vi'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
-su: vi:找不到命令

问题分析及解决办法:

这主要是路径问题,先查看$PATH变量的设置。
echo $PATH
里面的格式是xxx:xxx:xxx:xxx
这应该没包含/usr/bin这个路径。
执行下面命令就可以将这个路径包含进去:
export PATH=/usr/bin/:$PATH
如果要想每次登陆系统的时候,都自动包含这个路径,
可以把刚才这个命令加入到/root/.bash_profile或者/root/.bashrc文件的后面。

具体如下:
退回到普通用户(我的普通用户是lin)
lin@lenovo:~$ sudo gedit /root/.bash_profile
添加export PATH=/usr/bin/:$PATH,保存关闭.bash_profile文件
lin@lenovo:~$ su - root
口令:
root@lenovo:~# echo $PATH
/usr/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

root@lenovo:~# env
SHELL=/bin/bash
TERM=xterm
XDG_SESSION_COOKIE=f591adb565a6ba1bc40f9e954a26895b-1255053756.679619-1536901825
USER=root
MAIL=/var/mail/root
PATH=/usr/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/root
LANG=zh_CN.UTF-8
SHLVL=1
HOME=/root
LANGUAGE=zh_CN:zh
LOGNAME=root
_=/usr/bin/env

root@lenovo:~# vi
就可进行vi编辑了。

linux
相关资讯       Ubuntu知识 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款