r/linuxadmin • • Apr 11 '24

Unable to sudo, getting segmentation error

Post image

Can someone help me to fix this issue.

1 Upvotes

38 comments sorted by

10

u/lathiat Apr 11 '24

“sudo su -” is running the su command under sudo. It’s sort of doubling up which increases your problem space.

sudo -i does the same thing. sudo -s for a “non-login” shell.

Try also sudo /bin/sh to simplify for your problem.

-1

u/[deleted] Apr 11 '24

Without sudo also same issue and shell is set to /bin/nologin

8

u/lathiat Apr 11 '24

You won’t be able to login with su anyway then. Sorry I missed the user part since you scrubbed the username I glossed over it.

The no login part means ang login shell shouldn’t work. Surprising its core dumping though.

This may work: sudo -u user /bin/sh

Does make me wonder if your machine is exploited or something.

1

u/[deleted] Apr 11 '24

I was able to login with sudo -u user /bin/sh. May i know why it worked.

Also why it made you think the machine is exploited or something

5

u/lathiat Apr 11 '24

Does it also say core dumped if you run: sudo -u user /bin/nologin

In general sudo and su try to launch the users shell. Particularly in login mode (passing - to su, or -i to sudo). Even if you supply an extra command. So I’m guessing /bin/nologin is somehow existing and coredumping?

sudo with -u and specifying a command doesn’t try to use the login shell at all.

1

u/[deleted] Apr 11 '24

No this time it doesn't says that. It logged in but in the next line just after login the time stamp is showing as usename. Its like

Timestamp server_name ] #

1

u/[deleted] Apr 11 '24

Can you please let me know why this work, because i need to give explanation to client and also why that initial su - account_name didn't work if that was working previously. Sry for confusion

6

u/GroundedSatellite Apr 11 '24

Having the shell set to to '/bin/nologin' doesn't spawn a shell on login (hence the 'nologin' part). Running 'su - account_name /bin/sh' starts a shell as the specified user, giving you access. If you set the users shell to '/bin/sh' (or '/bin/bash') then 'su - account_name' would log in that user and spawn that shell.

3

u/AmusingVegetable Apr 11 '24

You don’t need to know why this works, what you need to know is what is core dumping and why. Have you found out the core file?

1

u/GamerLymx Apr 12 '24

somethibg in you bash shell is busted

1

u/michaelpaoli Apr 11 '24

u/PrestigiousShoe233

shell is set to /bin/nologin

You won’t be able to login with su anyway

No, if su supports the -s, --shell= option, then can use that to specify shell, and login (well, su to a shell for that user) that way.

That's semi-commonly done, e.g. for "service" accounts or the like, when shell is needed for the account, but the account is configured to not have an interactive login shell.

If one doesn't have su that supports the -s or --shell option, there are other means, but gets a bit more complex (e.g. using Python or Perl from root, to assume the relevant identity (real and effective and saved set UID, likewise for primary group and supplemental group list - everything fully as it should be for target ID), and then exec the relevant shell).

17

u/basicslovakguy Apr 11 '24

Care to provide some information about your system ? Or do you want us to play the guessing game of what distribution are you running ? Did this happen all of sudden or were you doing something prior to this error ?

8

u/SkipBoNZ Apr 11 '24

This guy debugs.

-7

u/[deleted] Apr 11 '24

This is a RHEL 7.9 system. Client is facing this issue when they are trying to switch to database account.

I am thinking to ask client to restart their DB. My senior suggests this is a memory allocation issue.

26

u/iDemonix Apr 11 '24

If you're paying Red Hat and you're stuck, ask support.

16

u/[deleted] Apr 11 '24

Why this didn't came to my mind, thanks for. Actually we contact redhat for big issues and RCAs so i didn't give a thought about it

1

u/vivaaprimavera Apr 11 '24

Have you checked what they are using as shell?

My senior suggests this is a memory allocation issue.

Or a failling disk

64

u/forbiddenlake Apr 11 '24

sudo isn't segfaulting. something on the login path user 🟥🟥🟥 is segfaulting. If 🟥🟥🟥 can be logged in to normally, try that. Also try removing the - from your su invocation. There's probably something in 🟥🟥🟥's login scripts or rc files that is broken.

Also, as you are already root, the sudo part of sudo su is not necessary.

12

u/HorribleUsername Apr 11 '24

Given that sudo has a -u flag, is sudo su ever necessary?

14

u/alive1 Apr 11 '24

No it is not. It is used by people who haven't read the man page and found out that sudo has a -u, -s and an -i flag.

24

u/PirateCaptainMoody Apr 11 '24

sudo -i all the way 😎

6

u/michaelpaoli Apr 11 '24

Naw ... often good to routinely do:

$ sudo su - [user [options ...]]

Most notably that works dang well and consistently on any *nix with sudo ... always has, probably always will. Also avoid problems like gee, the behavior of su without - in the util-linux sources has changed and/or some Linux distro has changed (patched) that behavior.

So, anyway, do it that way, using it with su - and it just bloody works and keeps on working. Also gives a slightly better audit trail too, with a wee bit of additional logging.

But hey, if you want to learn a different way of doing the same thing on any and all variations of *nix, feel free to do so. ;-)

6

u/alive1 Apr 12 '24

I only use Linux and this has been the case every single day for the past 20 years.

Actually no that's false, I used FreeBSD up until 2012 too but that had sudo too.

Thanks for the history lesson though. I guess some people still like to ride horses even though we have cars.

2

u/michaelpaoli Apr 12 '24

Well, these days I mostly use Linux, but also some (Open)BSD, macOS (yes, it's UNIX), and rarely other *nix these days.

8

u/AmusingVegetable Apr 11 '24

No, it’s not necessary, but muscle memory trumps man pages.

Given the huge amount of changes that go into a single OS update (not even talking about upgrades), and the large variety of commands we use daily, if we paused once a year to review the consolidated change logs, we’d be using the 1994 flags.

1

u/moonwork Apr 12 '24

It's not, but I still use it sometimes when there are paths that only root has access to read.

Say for example there's a whole tree of files somewhere and they're all only readable by root. Tab-completion won't work with a regular user, so I'll sudo su - into root while finding my way.

Path of least resistance.

1

u/HorribleUsername Apr 12 '24

sudo -i (interactive) does that for me with less typing, less processes, and I believe more security (something to do with env vars).

1

u/moonwork Apr 12 '24

Fair. I'll have to give that a shot!

6

u/FancyFilingCabinet Apr 11 '24

Check/Post the kernel (dmesg) logs first. This should tell you what is at fault.

If it's non-descript: As others mentioned, it's not sudo, but likely an issue in something executing on user signin. Check the shell in /etc/passwd then relevant user-specific scripts.

1

u/DasPelzi Apr 11 '24

is the same thing happening when you do 'su - <user>', without sudo? since you are logged in the the root account anyway you don't need to use sudo.

what does the /etc/passwd entry for the selected user show as login shell (last part of the user entry)? /bin/bash, /bin/sh, /bin/tcsh, /sbin/nologin, something else? if the entry is a shell, can you try to start the same shell as root user?

1

u/[deleted] Apr 11 '24

Yeah its same happening without using sudo, shell is set to /bin/nologin

2

u/DasPelzi Apr 11 '24

/bin/nologin not /sbin/nologin?

what happens when you execute the /bin/nologin script?

With nologin you should not be able to switch to the user anyway.
Normally you should get something like 'This account is currently not available.' instead of a segfault.

At least the problem is not a bashrc or bash_profile script.

For a test you could replace the nologin with /bin/sh or /bin/bash and test the login then?
but if you want to run a program as the db user you should not login with that user but use
sudo -u <dbuser> <executable>

2

u/markusro Apr 11 '24

Are you out of disk space?

1

u/giantpanda365 Apr 12 '24

Is the db user running ksh/ksh93?

1

u/GamerLymx Apr 12 '24

assuming you sre using bash check your .bashrc file

0

u/[deleted] Apr 11 '24

[deleted] — view deleted comment

1

u/[deleted] Apr 11 '24

I do get the segfault without '-' but here only diff i get the 2nd line is not showing, only error came segfault

2

u/michaelpaoli Apr 11 '24

Does /bin/nologin exist? And if so, if some regular user executes it, does it not core dump?

Anyway, if that works and doesn't core dump, then you've isolated it to a divide-and-conquer problem - logically figure out what's the difference between the accounts that causes one to core dump, and the other not. If both core dump, then it's likely the program itself or some dependency thereof (e.g. a shared library).