「sudo chmod +w /etc/hosts」を実行できません。

「sudo chmod +w /etc/hosts」を実行できません。

ESXiユーザーxyz(使用済み)としてリモート仮想マシンにログインしました。/etc/hostsデフォルトでは表示されないいくつかのネットワーク名を追加するために私のネットワーク名を変更したいと思います。

初めて走ろうとしました。

sudo vi /etc/hosts

ただし、と入力すると、viファイルが読み取り専用であるというメッセージが表示されます。次の権限があります。

>ls -l /etc/hosts
-rw-r--r-- 1 root root 416 2013-06-19 08:08 /etc/hosts

また、ほとんどすべての他のファイル/etcに。lsattr-----------------e-hosts----i------------e-

>lsattr /etc
...
-----------------e- ./python
----i------------e- ./hosts
...

それから私はこれを試してみました、chmodこれは私が得たものです。

>sudo chmod +w /etc/hosts
chmod: changing permissions of `/etc/hosts': Operation not permitted

sudoルート(ルートに切り替えるとき)はすべてを行うことができなければならないので、これが奇妙だと思います。私のsudoersファイルは非常に普通に見えます。

  1 # /etc/sudoers
  2 #
  3 # This file MUST be edited with the 'visudo' command as root.
  4 #
  5 # See the man page for details on how to write a sudoers file.
  6 #
  7 
  8 Defaults        env_reset
  9 
 10 # Host alias specification
 11 
 12 # User alias specification
 13 
 14 # Cmnd alias specification
 15 
 16 # User privilege specification
 17 root    ALL=(ALL) ALL
 18 
 19 # Allow members of group sudo to execute any command after they have
 20 # provided their password
 21 # (Note that later entries override this, so you might need to move
 22 # it further down)
 23 %sudo ALL=(ALL) ALL
 24 #
 25 #includedir /etc/sudoers.d
 26 
 27 # Members of the admin group may gain root privileges
 28 %admin ALL=(ALL) ALL

これが起こる理由と解決策の説明を探しています。

ベストアンサー1

この問題の具体的な属性は次iのとおりです。不変属性。

ファイルが表示されました。不変

これは、ルートを含むどのユーザーも変更できないことを意味します。ルートはまだ属性を変更して変更できない属性を削除できますが、ルートが単に無視できるファイルに対する標準の書き込み禁止権限とは異なり、ファイルを変更する前にそれを行う必要があります。

私が知る限り、これらの属性はext [234]ファイルシステムにのみ適用されます。

chattrのマニュアルページを見ることができます。

$man chattr

利用可能なプロパティの完全なリストと説明を確認してください。

私が実際に使用した唯一のものはiです。しかし、他のものは次のとおりです。

A: atime remains unmodified when accessed
a: can only be opened for writing in append-only mode
c: compressed automatically
j: all data is written to the journal before being written to the file
s: blocks are zeros when file is deleted
u: contents of file are saved when file is deleted for later undelete

他のプロパティもありますが、少し難解で、chattrのマニュアルページでより多くの情報を見つけることができます。

おすすめ記事