Linux to ask Password for Customized/Aliased Command? [closed] - linux

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am using alot of alias commands in Linux but how to protect each commands with p/w?
Lets say i made:
$ vi .bash_profile
alias goto1='echo ip=192.168.1.1, pw=abc; ssh root#192.168.1.1;'
alias goto2='echo ip=192.168.1.2, pw=xyz; ssh root#192.168.1.2;'
$ source .bash_profile
$ goto1
ip=192.168.1.1, pw=abc
root#192.168.1.1's password: _
That's the perfect taste of Unix/Linux based systems. And i'm using such things a lot!But the problem is:
How to protect these custom alias commands with password prompt?
For example, when i type $ goto1
Any bright idea!?

You can add those alias commands to (super_user) /root/.bashrc file.
Than you can use "sudo" restriction for normal user who wants to run that command with password or without password.
http://www.linux.com/learn/tutorials/306766-linux-101-introduction-to-sudo

You could put the credentials into a restricted permissions file eg
creds.txt
ip=192.168.1.1
pw=abc
then make it 0600 permissions so only you and root can read it. you alias would then be:
alias gotox='cat creds.txt; ssh root#<ip>;'
If another user trys to use the alias then they don't have permissions to read creds.txt and if they read your bashrc the sensitive info is not there.

Related

Tie a bash script to the ssh command [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Is there any way to edit the ssh command in such way that 'ssh hostname' runs a bash script first before its standard function
Edit: Note that the ssh command's name stays the same, without adding anything to it.
Use shell alias. In your case:
alias ssh="echo 'hi'; ssh "
From now on, when you type ssh in the terminal, the shell will expand the alias.
In a shell script, you would need shopt -s expand_aliases for it to work.
You can use ProxyCommand.
Add to your ~/.ssh/config:
Host hostname
ProxyCommand /path/to/bash-script

How to execute bash script without password? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I need to execute the script after system boot.
For example:
(sleep 5 && (sudo dhcpcd wlp4s0))
What I need: Executing the script.
What I have: [sudo] password for eugene:
I has been edited /etc/sudoers so:
eugene ALL=NOPASSWD: /home/eugene/dhcpcdstart.sh
But it's ineffectually. How I can to execute the current script without password?
Arch Linux 2013.05.01
I just tested your sudoers configuration and it works (not with dhcpcd, since I don't have it). Just make sure that you put that line at the end of sudoers file containing dhcpcd in the file list (I guess your script has executing rights for eugene user, but dhcpcd doesn't).
eugene ALL=NOPASSWD: dhcpcd_path/dhcpcd

Linux command line....How do I change from $ to #? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm working with the sed editor and I realize that my command prompt is:
[darkchild#localhost ~]$
How can I change this so that it ends in #....and what does this mean?
for example:
[darkchild#localhost ~]#
A friend told me to write this command #!/bin/bash but it does not change the prompt to #.
Can someone educate me?
Canonically # means root shell. You probably do not actually want to do this, because it would confuse other users of your system. If you do actually want to do this, you can edit the PROMPT variable.
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/
You can run the following command:
set prompt=\[`id -nu`#`hostname -s`\]\#\
This is the root user. You can go to this user using the su command.
More info: http://en.wikipedia.org/wiki/Su_(Unix)

difference in outputs of pwd and /bin/pwd [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
i created a soft link from my home folder to /etc/ by using
"ln -s /etc/ foo"
then i changed directory to foo
"cd foo"
now i executed the following two commands
"pwd" and "/bin/pwd"
Both gave me different outputs.
The output of "pwd" was /home/myhome/foo and of "/bin/pwd" was /etc.
I am not able to understand the difference in the outputs although both commands are the same.
Possibly a bit oversimplified, but the bash builtin pwd tracks cd commands, so when you cd through a symbolic link, it remembers that. On the other hand, /bin/pwd walks the directory tree back to the root, and, as such, has no idea what symbolic links you might have walked through to get where you are.

How to change Linux shell in a remote computer that does not support ypchsh [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How do I change shell in a remote PC? I am logged into a cluster with a Bash and the output I see is
elan#l01:~ $ chsh
chsh: can only change local entries; use ypchsh instead.
elan#l01:~ $ ypchsh
-bash: ypchsh: command not found
Since I have no root privilege there, I can not install ypchsh in the cluster. Is there any other way to change shell without invoking ypchsh?
Note 1:
Browsing, it looks like another user who installed the same software (currently not available for questioning) has .cshrc in his directory, with the right settings. His .bashrc is minimal and has no redirections.
The /etc/passwd has no entry for either of us.
getent passwd
shows entry for both of us, but shows only /bin/bash for both.
Note 2:
The sofware has been developed with autotools, and using bash instead of tcsh is known to have created wrong builds. (I am not changing shell because I fancy it.)
Thank you,
Elan
In your .bashrc, put exec tcsh last.
Once you're in bash in the cluster, why don't you just type tcsh? And if that works, why not just add it as the last line of .bashrc?

Resources