13

I created special user in /etc/passwd with:

secure:x:2000:2000:secure:/bin:/usr/sbin/nologin

I don't want to allow login of this user (via console, ssh, ftp, any way).

He is just for running one script via:

sudo su secure -c '/home/someuser/secure.script'

But it gives me This user is currently not available.. How to set it up to be able to run script this way but prevent any login (console, ssh, ftp,...) of this user to system?


I have noticed that when I type /usr/sbin/nologin on the command-line, the computer responds with This account is currently not available..

20

This is a typical use case for sudo.

You're mixing sudo which allows running commands as another user and is highly configurable (you can selectively specify which user can run which command as which user) and su which switches to another user if you know the password (or are root). su always runs the shell written in /etc/passwd, even if su -c is used. Because of this su isn't compatible with /usr/sbin/nologin.

You should use

sudo -u secure /home/someuser/secure.script

As sudo is configurable you can control who can use this command and if he/she needs to enter a password to run it. You need to edit /etc/sudoers using visudo to do this. (Be careful when editing /etc/sudoers and always use visudo to do it. The syntax isn't trivial and one error can lock you out from your root account.)

This line in sudoers allows anyone in group somegroup to run the command as secure:

%somegroup    ALL=(secure) /home/someuser/secure.script

This allows anyone in group somegroup to run the command as secure without entering a password:

%somegroup    ALL=(secure) NOPASSWD: /home/someuser/secure.script

This allows user1 to run the command as secure without entering a password:

user1    ALL=(secure) /home/someuser/secure.script
7

I found out the main problem is "/usr/sbin/nologin" in /etc/passwd When I want to execute su in this case, it must have -s /bin/bash inside, so for example: su -s /bin/bash -c '/home/someuser/secure.script' secure

  • 1
    Yes, su uses the shell written in /etc/passwd by default. Using su is a way to login as a user from another user. nologin prints the message "This user is currently not available." and exits. sudo doesn't use a shell to execute a command, so using sudo without su will also work. See my answer for more about sudo. – cg909 Apr 13 '17 at 23:27
2

su is using the shell specified in /etc/passwd.

You don't need to use su with sudo.

Therefore don't mix su with sudo: use sudo -u secure '/home/someuser/secure.script'.

-2

This might not be 100% relevant to the question but may help someone who had similar warning message This user is currently not available

1) Check with your hosting company if you have been grant shell access.

2) if you are using CWP7: Set Shell Access To ON enter image description here

  • 2
    1) Shell access is clearly available as the question talks about running su, sudo and all sorts of other things. 2) There is no indication in the question that the installation in question is behind a web control panel of any form. – Philip Kendall Aug 20 '18 at 21:00
  • 1
    Yes (other than it's a Q&A site, not a forum). But part of being helpful is ensuring that your answer is actually relevant to the question, and I don't think that this answer is actually relevant: the poster clearly has shell access already, so how would turning it on via a control panel (which may not even exist) solve the problem? – Philip Kendall Aug 22 '18 at 19:11
  • 3
    @ShapCyber: Notice that this question deals with someone who manually created a new, special user on their own. The answers in this "thread" (Question) should address the situation in that question. If you've encountered a different problem that has this as a solution, the right thing to do is to Ask and Self-Answer your own new question. – Jeff Schaller Aug 22 '18 at 19:27
  • 1
    What @JeffSchaller said is correct. And I would encourage you, ShapCyber, to really do please ask and self-answer a question with the problem and solution you encountered (in enough detail to be useful); and then add a comment to this question to link to yours. That's how to best help future readers in the framework of how this site is set up. :) – Wildcard Aug 22 '18 at 19:36
  • 2
    @ShapCyber that’s why we’re encouraging you to open a new question, so that searches find the right answer for their problem. – Jeff Schaller Aug 22 '18 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.