Why doesn't `sudo cd /var/named` work?

朴灿烈づ我的快乐病毒、 2022-06-18 08:14 190阅读 0赞

Question:

I want to cd into /var/named but it gives me a permission denied error, and when I want to use sudo to do this I am not permitted. What is the technical reason for this, and is it possible to do this some other way?

Answer:

The reason you can’t do this is simple and two fold

1

cd is not a program but an in-built command and sudo only applies to programs.

sudo foo means run the program foo as root

sudo cd /path returns

  1. sudo: cd: command not found

because cd is not a program.

2

If it were possible to use sudo to cd to a protected directory then having run the command sudo cd /var/named you would be in that directory as a normal user but normal users are not allowed to be in that directory.

This is not possible.

Workaround:

You can use sudo -i to elevate yourself to super user. For example:

  1. sudo -i
  2. cd /var/named

You are now logged on as root and can use whatever commands you wish. When finished type exit and you are back to being logged on as a normal user.

发表评论

表情:
评论列表 (有 0 条评论,190人围观)

还没有评论,来说两句吧...

相关阅读

    相关 5 WHY

    简介 所谓5why分析法,又称“5问法”,也就是对一个问题点连续以5个“为什么”来自问,以追究其根本原因。 虽为5个为什么,但使用时不限定只做“5次为什么的探讨”,主要是必

    相关 Why Spring Boot

    本文介绍将各种Spring的配置方式,帮助您了解配置Spring应用的复杂性。 Spring是一个非常受欢迎的Java框架,它用于构建web和企业应用。不像许多其他框架只关注

    相关 Why I Began

    最近有很多同学加我微信,问一些求职相关的疑问,有的同学末了会问一个问题: “师兄,为什么要转发推广啊,你是想创业吗?”   创业?从注册公众号到现在或者说二十多年以来,这