LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-03-2022, 05:41 AM   #1
vucni45
Member
 
Registered: Aug 2021
Posts: 38

Rep: Reputation: Disabled
shadow


hi,
I like to know why with passwd or sed i can write in /etc/shadow and with vi i can not write.


ls -l /etc/shadow
----------. 1 root root 1242 Jul 3 06:36 /etc/shadow
ls -l /usr/bin/sed
-rwxr-xr-x. 1 root root 76072 Sep 30 2020 /usr/bin/sed
ls -l /usr/bin/vi
-rwxr-xr-x. 1 root root 928304 Dec 15 2020 /usr/bin/vi
 
Old 07-03-2022, 08:39 AM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,613

Rep: Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695
A single word subject is far less likely to result in meaningful answers. Your question or subject should be clear in summery or context from the subject of the thread whenever possible.

Examples please
It does not help to ask a question about behavior, without enough details for us to replicate the behavior.

Passwd can modify /etc/shadow because it can do so under root authority, vi cannot unless you run IT under root authority.
(Why exactly would anyone want to DO that?)

I have migrated accounts between servers in an enterprise environment that required me to directly modify those files, but there has never otherwise been need.

What are you trying to do?
 
Old 07-04-2022, 02:46 AM   #3
vucni45
Member
 
Registered: Aug 2021
Posts: 38

Original Poster
Rep: Reputation: Disabled
hi,
i used vi with root user and i can not write in /etc/shadow.
 
Old 07-04-2022, 04:53 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,830

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
you must not directly write (modify) /etc/shadow. That is a special purpose system file and there are special tools to handle it (like passwd). Incorrect /etc/shadow file may make your system useless.
 
Old 07-04-2022, 11:52 AM   #5
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,613

Rep: Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695
Quote:
Originally Posted by vucni45 View Post
hi,
i used vi with root user and i can not write in /etc/shadow.
If you do not know how to make that work, you should not be trying to make that work! Just sayin'
 
1 members found this post helpful.
Old 07-04-2022, 03:51 PM   #6
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 997

Rep: Reputation: 382Reputation: 382Reputation: 382Reputation: 382
# ls -l /etc/shadow

Is the owner allowed to write to it? (No: see #1)
Maybe Also show the output of lsattr And df -T /etc

Try: :w! in vi

man vipw

Web research to learn about ownership and permissions, which are very basic to linux.
https://launchschool.com/books/comma...ad/permissions

Best wishes!!! @OP: click Edit & then 'Go advanced' on #1, to enhance the subject


Quote:
The root user will be able to reset what ever restriction you put on the file.
Darn, and I thot I knew SunOS4 Unix... anyone know what man page says that?

Last edited by !!!; 07-10-2022 at 11:14 AM.
 
Old 07-05-2022, 05:30 AM   #7
vucni45
Member
 
Registered: Aug 2021
Posts: 38

Original Poster
Rep: Reputation: Disabled
you wpeckham are are big idiot.i know that i never must edit shadow but this was a simple curiosity.none of you guy here know the answer.
i will never go down of your low skills wpeckham.your attitude tell me everything about you-you are nobody as person and nobody in linux.

you do not deserve to work in linux.
its to much for you.
 
Old 07-05-2022, 05:41 AM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,691

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
Per the rules
Quote:
Do not post any messages that are obscene, vulgar, sexually-orientated, hateful, threatening, hostile or insulting.
Personal attacks on others will not be tolerated.
Regardless of what command, you either need to be root or use sudo to edit the file.
vi has an edit mode. If not in edit mode you can not write to the file.
 
2 members found this post helpful.
Old 07-05-2022, 06:26 AM   #9
SlowCoder
Senior Member
 
Registered: Oct 2004
Location: Southeast, U.S.A.
Distribution: Debian based
Posts: 1,250

Rep: Reputation: 164Reputation: 164
Quote:
Originally Posted by vucni45 View Post
you wpeckham are are big idiot.i know that i never must edit shadow but this was a simple curiosity.none of you guy here know the answer.
i will never go down of your low skills wpeckham.your attitude tell me everything about you-you are nobody as person and nobody in linux.

you do not deserve to work in linux.
its to much for you.
@vucni45, do you consider this an acceptable way to talk to peers, especially those trying to help?

You said: "I like to know why with passwd or sed i can write in /etc/shadow and with vi i can not write."
In other words, you asked why you can't modify the file.
wpeckham helpfully responded that it would not be advisable, and provided details.
 
1 members found this post helpful.
Old 07-05-2022, 12:10 PM   #10
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,613

Rep: Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695
Quote:
Originally Posted by vucni45 View Post
you wpeckham are are big idiot.i know that i never must edit shadow but this was a simple curiosity.none of you guy here know the answer.
i will never go down of your low skills wpeckham.your attitude tell me everything about you-you are nobody as person and nobody in linux.

you do not deserve to work in linux.
its to much for you.
Seriously kid? I have done this for a lifetime, remember when the shadow systems were NEW and not required, and am ready to retire. I do this stuff ALL the time. I have shot myself in the foot a few times along the way. I cannot stop you from that, but I can at least point out which toe you are aiming at and refuse to load the gun.


The shadow system is pretty well documented, and there is no real mystery about permissions and authority. The evidences and detail is right in front of you. If you have not figured this out, you are not ready. If you HAVE figured it out, you are not likely to be ready: if you were you would not be so aggressive/defensive about things. IF you experiment with making those changes manually please start on a system where you have time and leisure to figure things out when it all blows up on you, because that is a very real possibility!

You can figure this out. You can learn this, and have been given all the right tools. When you do, also try to learn some manners, that lesson will serve you better in life than ANYTHING we could put in a lifetime of posts.
 
1 members found this post helpful.
Old 07-10-2022, 03:48 AM   #11
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,789

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
root (UID 0) can write to files even if not allowed by the permissions. (Coded in the kernel.)

vim (vi) is extra cautious.
Force-write with :w!

A little safer is
vipw -s
Of course there are tools to safely manipulate certain fields in /etc/shadow

The dot in ls -l means there is a selinux context.
This is a kind of extra permissions that only exist in memory, initialized from a rule table.
Show them with ls -Z
Normally /etc/shadow inherits the selinux context from the directory /etc (or gets it from a dedicated rule).
If you extract it from an archive or move it from another directory or copy it with cp -a then the selinux context changes.
It can be quickly restored with restorecon.
A selinux access denial is logged in the syslog messages.

Last edited by MadeInGermany; 07-10-2022 at 05:04 AM.
 
1 members found this post helpful.
Old 07-10-2022, 07:20 PM   #12
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 997

Rep: Reputation: 382Reputation: 382Reputation: 382Reputation: 382
Thanks @#11!!!

Is the reason that sed -i works, the exact same as the way the vi :w! Works? And the same as > or any other thing that writes to it would succeed by default?

All being the same reason that you wrote in the beginning, that that's the way the kernel works?
 
Old 07-11-2022, 12:08 AM   #13
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,830

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
Quote:
Originally Posted by !!! View Post
Thanks @#11!!!

Is the reason that sed -i works, the exact same as the way the vi :w! Works? And the same as > or any other thing that writes to it would succeed by default?

All being the same reason that you wrote in the beginning, that that's the way the kernel works?
I just don't understand the question. All tools work the same, if we want to write a file, they will do it if the permission settings allow it.
Some of them may have an "are you sure" box or something similar.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LFS 11.0: 8.25. Shadow: Invalid /etc/shadow permissions after pwconv ClemaX Linux From Scratch 2 12-25-2021 01:01 PM
ubuntu karmic nis client 'ypcat shadow.byname' works, but 'getent shadow' fails casterln Linux - Networking 1 03-06-2010 01:47 AM
/etc/shadow- (notice the dash after the word shadow) shellcode Linux - Security 1 09-03-2004 04:54 AM
/etc/shadow and apache gorang Linux - General 1 11-18-2001 04:50 AM
/etc/shadow in user authentication katana Linux - General 3 06-24-2001 11:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration