LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Arch (https://www.linuxquestions.org/questions/arch-29/)
-   -   "su: authentication failure" after attempting to fix "bash: bad interpreter: Permission denied" error (https://www.linuxquestions.org/questions/arch-29/su-authentication-failure-after-attempting-to-fix-bash-bad-interpreter-permission-denied-error-4175715642/)

AKM512 08-13-2022 05:49 PM

"su: authentication failure" after attempting to fix "bash: bad interpreter: Permission denied" error
 
I'm trying to learn bash shell scripting, and I've run into a series of related issues. I can't execute the
Code:

mkfile.sh
script in this Wikibook course, leading to this sequence of issues:

Code:

[austin@archlinux bash]$ ./mkfile.sh filetocreatetext.txt 'line to put in file'
bash: ./mkfile.sh: /home/austin/bash: bad interpreter: Permission denied
[austin@archlinux bash]$ chmod +x mkfile.sh
[austin@archlinux bash]$ ./mkfile.sh filetocreatetext.txt 'line to put in file'
bash: ./mkfile.sh: /home/austin/bash: bad interpreter: Permission denied
[austin@archlinux bash]$ sudo chmod +x mkfile.sh
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
[austin@archlinux bash]$ bash for3.sh
bash: for3.sh: No such file or directory
[austin@archlinux bash]$ bash for_2.sh
1
3
5
7
9
11
[austin@archlinux bash]$ sudo chmod +x mkfile.sh
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
[austin@archlinux bash]$ sudo pkexec chmod 4755 /usr/bin/sudo
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
[austin@archlinux bash]$ sudo --help
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
[austin@archlinux bash]$ man sudo
[austin@archlinux bash]$ chmod +x mkfile.sh
[austin@archlinux bash]$ emacs mkfile.sh
[austin@archlinux bash]$ ./mkfile.sh file-to-create.txt line to put in file
bash: ./mkfile.sh: /home/austin/bash: bad interpreter: Permission denied

Though I was extremely weary of trying the solution here because of the dangers of working as root with
Code:

su
, I couldn't find any other obvious alternatives that didn't require logging in as root online.

Quote:

austin@archlinux bash]$ su
Password:
su: Authentication failure
[austin@archlinux bash]$ su
Password:
su: Authentication failure
[austin@archlinux bash]$ sudo -i
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
[austin@archlinux bash]$ su austin
Password:
su: Authentication service cannot retrieve authentication info
[austin@archlinux bash]$ sudo -s
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
I know I must have the correct root password, because I used it to put myself in the sudoers file when I installed my Arch system. I'm not very experienced, so I'm very hesitant to try this solution using
Code:

sudo su
from AskUbuntu (plus, I'm obviously not running Ubuntu or even a Debian-based distro.)

Would it even be possible to reset my root password using
Code:

sudo su
? I'm pretty sure my password is correct, if nothing else because it's identical to my regular user (e.g.
Code:

austin
) password. (Yes, I know that's insecure and probably foolish, but I am where I am now; I don't intend to do it again.)

michaelk 08-13-2022 10:24 PM

The two errors are unrelated to each other. The bad interpreter is probably due to a bad shebang line i.e. #!/bin/bash. Without seeing your script it is difficult to say what is wrong. Did you write the script using windows and copied to linux?

AKM512 08-13-2022 11:41 PM

Quote:

Originally Posted by michaelk (Post 6373590)
The two errors are unrelated to each other. The bad interpreter is probably due to a bad shebang line i.e. #!/bin/bash. Without seeing your script it is difficult to say what is wrong. Did you write the script using windows and copied to linux?

Here is the contents of
Code:

mkfile.sh
, located under
Code:

/home/austin/bash
:

Code:

#!/home/austin/bash

file="$1" # save the first argument as "$file"
shift # drop the first argument from "$@"
echo "$@" > "$file" # write the remaining arguments to "$file"

I cut and pasted the code from the Wikibooks course here.

Is the shebang line wrong? I've used an identical line for every script I've written so far, located at
Code:

home/austin/bash
.

No Windows computer was involved in the construction/copying of this script or any files; all of this was done on my Arch Linux laptop.

suramya 08-14-2022 12:26 AM

Quote:

Originally Posted by AKM512 (Post 6373594)
Code:

#!/home/austin/bash

file="$1" # save the first argument as "$file"
shift # drop the first argument from "$@"
echo "$@" > "$file" # write the remaining arguments to "$file"


The first line should point to the Bash executable. On my system it is at: /usr/bin/bash You can run 'whereis bash' (without the quotes) to get the location on your system.

/home/austin/bash is a directory and thus not an interpreter.

AKM512 08-14-2022 01:29 AM

Quote:

Originally Posted by suramya (Post 6373596)
The first line should point to the Bash executable. On my system it is at: /usr/bin/bash You can run 'whereis bash' (without the quotes) to get the location on your system.

/home/austin/bash is a directory and thus not an interpreter.

Ah, my misunderstanding. I thought the shebang was supposed to be the path to the file on the file system.

That seems to have done the trick (I don't get an error message anymore); I changed the shebang to
Code:

#!/usr/bin/bash
.

Code:

[austin@archlinux bash]$ ./mkfile.sh file-to-create.txt line to put in file
[austin@archlinux bash]$ emacs mkfile.sh

I will mark as solved. Thanks!

pan64 08-14-2022 02:00 AM

just a comment: you must not use sudo and su together, that is not a good advice.

boughtonp 08-14-2022 10:35 AM


 
That entire "mkfile.sh" script is plain stupid - if the rest of the guide uses similar examples, I'd recommend a different guide.

Here's one: https://mywiki.wooledge.org/BashGuide


AKM512 08-14-2022 10:43 AM

Quote:

Originally Posted by boughtonp (Post 6373678)
That entire "mkfile.sh" script is plain stupid - if the rest of the guide uses similar examples, I'd recommend a different guide.

Here's one: https://mywiki.wooledge.org/BashGuide


Thanks for the link; I'll use it instead.


All times are GMT -5. The time now is 01:28 PM.