Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: passwords with special characters are trying to kill me... no seriously!

by ikegami (Pope)
on Feb 04, 2011 at 17:55 UTC ( #886262=note: print w/replies, xml ) Need Help??


in reply to Re^2: passwords with special characters are trying to kill me... no seriously!
in thread passwords with special characters are trying to kill me... no seriously!

It's easy if you build the command in stages.

sub text_to_shell_lit(_) { return $_[0] if $_[0] =~ /^[a-zA-Z0-9_\-]+\z/; my $s = $_[0]; $s =~ s/'/'\\''/g; return "'$s'"; } my $user = 'bob'; my $passwd = 'test$ing'; my $echo_cmd = join ' ', map text_to_shell_lit, echo => $passwd; my $passwd_cmd = join ' ', map text_to_shell_lit, passwd => '--', $user; my $ssh_cmd = join ' ', map text_to_shell_lit, ssh => 'hostname', "$echo_cmd | $passwd_cmd";
ssh hostname 'echo '\''test$ing'\'' | passwd -- bob'

Note that command lines are readable by anyone on the machine. It is not safe to pass passwords in command lines. Yet another reason why opening a pipe to ssh is better.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://886262]
help
Chatterbox?
[pryrt]: Thus, that's "enough precision" to tell the difference between 1.0 and 1.0+1ULP
[pryrt]: But in what circumstance does your problem arise? When, in Perl, does the integer 1 not work identically to the floating-point NV 1.0000000000000000 e0?

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (16)
As of 2017-05-24 19:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?