Provide password for running a script inside another script as different user

Imagine you run script as user A: sudo -u A ./
Inside that we have a line that calls another script with a different user B: sudo -u B ./ Now I get prompted to enter a password for user B. Is there any way to provide that password uppon call?

P.S. I know all the security breaches it can create. Please do not mention me that.


Yes you have option for that. But that password you have to provide at the time of executing the script or hard coded it in the script itself. Try with the below example:-

echo 'passwordofB' | sudo -u B -S ./

Also you can do it like:-

 sudo -u A ./ passwordofB #as a command line parameter

now inside

echo $1 | sudo -u B -S ./

You are executing another script sudo -u B ./ from script ./ right? So change that line with echo $1 | sudo -u B -S ./ and run your first script as sudo -u A ./ passwordofB where passwordofB is the password for user ‘B’


sudo: sorry, you must have a tty to run sudo

Replace Defaults requiretty by Defaults !requiretty in your /etc/sudoers. This will impact your global sudo configuration.

How to fix ‘sudo: no tty present and no askpass program specified’ error?

  1. Use NOPASSWD line for all commands, I mean:
    jenkins ALL=(ALL) NOPASSWD: ALL
  2. Put the line after all other lines in the sudoers file.

How to give user sudo less access to command

Edit the file /etc/sudoers:

Cmnd_Alias JENKINS_CMDS = /bin/systemctl start jenkins, /bin/systemctl restart jenkins, /bin/systemctl stop jenkins, /bin/systemctl status jenkins

This will give jenkins group access to commands in JENKINS_CMDS


Linux commands

sudo!! : Forgot to run a command with sudo? You need not re-write the whole command, just type “sudo!!” and the last command will run with sudo.

2. Python -m SimpleHTTPServer : Creates a simple web page for the current working directory over port 8000.

3. mtr : A command which is a combination of ‘ping’ and ‘traceroute’ command.

4. Ctrl+x+e : This key combination fires up, an editor in the terminal, instantaneously.

5. nl : Outputs the content of text file with lines Numbered.

6. shuf : Randomly selects line/file/folder from a file/folder.

7. ss : Outputs Socket Statistics.

8. Last: Want to know history of last logged in users? This command comes to rescue here.

9. curl : Shows machine’s external IP Address.

10. tree : Prints files and folders in tree like fashion, recursively.

11. Pstree : Prints running processes with child processes, recursively.

13. stat : Shows the status information of a file as well as of a file system.

15. Pv : outputs simulating text, similar to hollywood movies.

16. Mount | column -t : Lists mounted file system, in nice formatting with specification.

17. Ctrl + l: clear shell prompt, instantaneously.

18. curl -u gmail_id –silent “” | perl -ne ‘print “\t” if //; print “$2\n” if /(.*)/;’. This simple scripts, opens up, unread mail of an user, in the terminal itself.

19. screen : Detach and Reattach, long running process from a session.

20. file : Outputs information, regarding types of file.

21. id : Print User and Group Id.
22. ^foo^bar : Run last command with modification, without the need of rewriting the whole command again.

24. at : Run a particular command, time based.

25. du -h –max-depth=1 Command : Outputs the size of all the files and folders within current folder, in human readable format.

26. expr : Solve simple mathematical calculations from the terminal.

27. look: Check for an English word, from the dictionary, in case of confusion, right from the shell.

28. yes : continues to print a sting, till interrupt instruction is given.

29. factor: Gives all the possible factors of a decimal number.

30. ping -i 60 -a IP_address : Pings the provided IP_address, and gives audible sound when host comes alive.

31. tac : Prints content of a file, in reverse order.

32. strace : A debugging tool.

33. disown -a && exit Command : Run a command in background, even after terminal session is closed.

34. getconf LONG_BIT Command : Output Machine Architecture, very clearly.

35. while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done & : The script outputs date and time on the top right corner of shell/ terminal.

36. convert : converts the output of a command in picture, automatically.

37. watch -t -n1 “date +%T|figlet” : Show animated digital clock at the prompt.

38. host and dig : DNS lookup utility.

39. dstat : Generates statistics regarding system resource.

40. bind -p : Shows all the shortcuts available in Bash.

41. Touch /forcefsck : Force file-system check on next boot.

42. lsb_release : Prints distribution specification information.

43. nc -ZV localhost port_number : Check if a specific port is open or not.

44. curl : Outputs Geographical Information, regarding an ip_address.

45. find .-user xyz : Lists all file owned by user ‘xyz’

46. apt-get build-dep package_name: Build all the dependency, automatically while installing any specific package.

47. lsof -iTCP:80 -sTCP:LISTEN. The script, outputs all the service/process using port 80.

48. find -size +100M : This command combination, Lists all the files/folders the size of which is 100M or more.

49. pdftk : A nice way to concatenate a lot of pdf files, into one.

50. ps -LF -u user_name : Outputs Processes and Threads of a user.

51. Startx — :1 (This command creates another new X session).

top 6 files that eat up your space:

du -hsx * | sort -rh | head -6
  • Alt+Backspace: Deletes the previous word.
  • Alt+F: Skips ahead to the next space.
  • Alt+B: Skips back to the previous space.
  • Ctrl+U: Cuts all text up to the cursor.
  • Ctrl+K: Cuts all text after the cursor until end of line.
  • Ctrl+A: Moves the cursor to the start of line.
  • Ctrl+E: Moves the cursor to the end of line.