Shell Script on Debian

View: New views
9 Messages — Rating Filter:   Alert me  

Shell Script on Debian

by Phuong Phan Thi Bach :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
The  "passwd" command expects to read the new password only from the console, How to it read the new password only from a file.  I create a file (Ex: test file )

test file
123456
123456
After, I use: "passwd < test" (shell on Debian is sh)
But it always error: "Enter new UNIX password: Retype new UNIX password:  Sorry, passwords do not match"
Please, could you help me.
Best regards,
Phuong

Re: Shell Script on Debian

by David Weinehall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Jun 27, 2008 at 11:45:45AM +0700, Phuong Phan Thi Bach wrote:

> Hello,
> The  "passwd" command expects to read the new password only from the
> console, How to it read the new password only from a file.  I create a file
> (Ex: test file )
>
> test file
> 123456
> 123456
> After, I use: "*passwd < test*" (shell on Debian is sh)
> But it always error: "Enter new UNIX password: Retype new UNIX password:
> Sorry, passwords do not match"
> Please, could you help me.
> Best regards,
> Phuong

Use chpasswd, it supports batch processing.


Regards: David Weinehall
--
 /) David Weinehall <tao@...> /) Rime on my window           (\
//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   //  Diamond-white roses of fire //
\)  http://www.acc.umu.se/~tao/    (/   Beautiful hoar-frost       (/


--
To UNSUBSCRIBE, email to debian-arm-REQUEST@...
with a subject of "unsubscribe". Trouble? Contact listmaster@...


Re: Shell Script on Debian

by ApOgEE :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
There is another way... Here's my way to do it:
copy and paste this command:

$ cat > chpass << EOF
#!/bin/sh
# \\
exec expect -f "\$0" \${1+"\$@"}
set password [lindex \$argv 1]
spawn passwd [lindex \$argv 0]
sleep 1
expect "assword:"
send "\$password\r"
expect "assword:"
send "\$password\r"
expect eof
EOF


Then issue this command:
$ chmod +x chpass


to test it, just try this command:
$ ./chpass <username> <newpassword>

for example:
root@mydebian:root# /root/chpass root mynewrootpass
spawn passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@mydebian:root#

Good Luck!!



On Fri, Jun 27, 2008 at 12:45 PM, Phuong Phan Thi Bach
<ptbphuong@...> wrote:

> Hello,
> The  "passwd" command expects to read the new password only from the
> console, How to it read the new password only from a file.  I create a file
> (Ex: test file )
>
> test file
> 123456
> 123456
> After, I use: "passwd < test" (shell on Debian is sh)
> But it always error: "Enter new UNIX password: Retype new UNIX password:
> Sorry, passwords do not match"
> Please, could you help me.
> Best regards,
> Phuong
>



--
Best Wishes,

ApOgEE a.k.a JeRuNgKuN
----------------------------------------------------
https://edge.launchpad.net/~apogee - ApOgEE on LaunchPad
http://artofapogee.blogspot.com - Art Of ApOgEE
http://coderstalk.blogspot.com - Coder's Talk
http://jerungkun.blogspot.com - The Rojak Blog
http://reggae-and-ska.blogspot.com - Reggae and SKA Music Blog
----------------------------------------------------


--
To UNSUBSCRIBE, email to debian-arm-REQUEST@...
with a subject of "unsubscribe". Trouble? Contact listmaster@...


Re: Shell Script on Debian

by ApOgEE :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Owh, another thing... make sure you've installed 'expect'

# apt-get install expect

Good Luck!!


On Fri, Jun 27, 2008 at 4:50 PM, ApOgEE <jerungkun@...> wrote:

> Hi,
> There is another way... Here's my way to do it:
> copy and paste this command:
>
> $ cat > chpass << EOF
> #!/bin/sh
> # \\
> exec expect -f "\$0" \${1+"\$@"}
> set password [lindex \$argv 1]
> spawn passwd [lindex \$argv 0]
> sleep 1
> expect "assword:"
> send "\$password\r"
> expect "assword:"
> send "\$password\r"
> expect eof
> EOF
>
>
> Then issue this command:
> $ chmod +x chpass
>
>
> to test it, just try this command:
> $ ./chpass <username> <newpassword>
>
> for example:
> root@mydebian:root# /root/chpass root mynewrootpass
> spawn passwd root
> Enter new UNIX password:
> Retype new UNIX password:
> passwd: password updated successfully
> root@mydebian:root#
>
> Good Luck!!
>
>
>
> On Fri, Jun 27, 2008 at 12:45 PM, Phuong Phan Thi Bach
> <ptbphuong@...> wrote:
>> Hello,
>> The  "passwd" command expects to read the new password only from the
>> console, How to it read the new password only from a file.  I create a file
>> (Ex: test file )
>>
>> test file
>> 123456
>> 123456
>> After, I use: "passwd < test" (shell on Debian is sh)
>> But it always error: "Enter new UNIX password: Retype new UNIX password:
>> Sorry, passwords do not match"
>> Please, could you help me.
>> Best regards,
>> Phuong
>>
>
>
>
> --
> Best Wishes,
>
> ApOgEE a.k.a JeRuNgKuN
> ----------------------------------------------------
> https://edge.launchpad.net/~apogee - ApOgEE on LaunchPad
> http://artofapogee.blogspot.com - Art Of ApOgEE
> http://coderstalk.blogspot.com - Coder's Talk
> http://jerungkun.blogspot.com - The Rojak Blog
> http://reggae-and-ska.blogspot.com - Reggae and SKA Music Blog
> ----------------------------------------------------
>



--
Best Wishes,

ApOgEE a.k.a JeRuNgKuN
----------------------------------------------------
https://edge.launchpad.net/~apogee - ApOgEE on LaunchPad
http://artofapogee.blogspot.com - Art Of ApOgEE
http://coderstalk.blogspot.com - Coder's Talk
http://jerungkun.blogspot.com - The Rojak Blog
http://reggae-and-ska.blogspot.com - Reggae and SKA Music Blog
----------------------------------------------------


--
To UNSUBSCRIBE, email to debian-arm-REQUEST@...
with a subject of "unsubscribe". Trouble? Contact listmaster@...


Re: Shell Script on Debian

by Mike Pellatt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I presume everyone is aware of the risks associated with storing
plaintext passwords in any file, including script files, and the ways of
reducing (but not eliminating) said risks.....

For example (but by no means exhaustively) I wouldn't do chmod +x on the
file, but would do chmod u+x. and also go-rwx, unless I had extremely
compelling reasons otherwise.

Mike
Continuing an off-topic thread, I know, but......

ApOgEE wrote:

> Owh, another thing... make sure you've installed 'expect'
>
> # apt-get install expect
>
> Good Luck!!
>
>
> On Fri, Jun 27, 2008 at 4:50 PM, ApOgEE <jerungkun@...> wrote:
>  
>> Hi,
>> There is another way... Here's my way to do it:
>> copy and paste this command:
>>
>> $ cat > chpass << EOF
>> #!/bin/sh
>> # \\
>> exec expect -f "\$0" \${1+"\$@"}
>> set password [lindex \$argv 1]
>> spawn passwd [lindex \$argv 0]
>> sleep 1
>> expect "assword:"
>> send "\$password\r"
>> expect "assword:"
>> send "\$password\r"
>> expect eof
>> EOF
>>
>>
>> Then issue this command:
>> $ chmod +x chpass
>>
>>
>> to test it, just try this command:
>> $ ./chpass <username> <newpassword>
>>
>> for example:
>> root@mydebian:root# /root/chpass root mynewrootpass
>> spawn passwd root
>> Enter new UNIX password:
>> Retype new UNIX password:
>> passwd: password updated successfully
>> root@mydebian:root#
>>
>> Good Luck!!
>>
>>
>>
>> On Fri, Jun 27, 2008 at 12:45 PM, Phuong Phan Thi Bach
>> <ptbphuong@...> wrote:
>>    
>>> Hello,
>>> The  "passwd" command expects to read the new password only from the
>>> console, How to it read the new password only from a file.  I create a file
>>> (Ex: test file )
>>>
>>> test file
>>> 123456
>>> 123456
>>> After, I use: "passwd < test" (shell on Debian is sh)
>>> But it always error: "Enter new UNIX password: Retype new UNIX password:
>>> Sorry, passwords do not match"
>>> Please, could you help me.
>>> Best regards,
>>> Phuong
>>>
>>>
>>>      


--
To UNSUBSCRIBE, email to debian-arm-REQUEST@...
with a subject of "unsubscribe". Trouble? Contact listmaster@...


Re: Shell Script on Debian

by Loic Minier :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 (Not quite sure how this relates to arm.)

On Fri, Jun 27, 2008, ApOgEE wrote:
> set password [lindex \$argv 1]

 The command line might be visible by all users of the system, unless
 you use some locked down kernel, so I wouldn't pass the password on the
 command line.

--
Loïc Minier


--
To UNSUBSCRIBE, email to debian-arm-REQUEST@...
with a subject of "unsubscribe". Trouble? Contact listmaster@...


Re: Shell Script on Debian

by ApOgEE :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

Thanks for all comments, that code may not good for security reason.
Hope you can suggest the more secure and proper way to do so. Since
the purpose of creating that script as for me is to be able to use
script to change the password from other interface for example from a
PHP web interface.

Currently, that's what I found works for my system.


On Fri, Jun 27, 2008 at 5:42 PM, Loïc Minier <lool@...> wrote:

>  (Not quite sure how this relates to arm.)
>
> On Fri, Jun 27, 2008, ApOgEE wrote:
>> set password [lindex \$argv 1]
>
>  The command line might be visible by all users of the system, unless
>  you use some locked down kernel, so I wouldn't pass the password on the
>  command line.
>
> --
> Loïc Minier
>
>
> --
> To UNSUBSCRIBE, email to debian-arm-REQUEST@...
> with a subject of "unsubscribe". Trouble? Contact listmaster@...
>
>



--
Best Wishes,

ApOgEE a.k.a JeRuNgKuN
----------------------------------------------------
https://edge.launchpad.net/~apogee - ApOgEE on LaunchPad
http://artofapogee.blogspot.com - Art Of ApOgEE
http://coderstalk.blogspot.com - Coder's Talk
http://jerungkun.blogspot.com - The Rojak Blog
http://reggae-and-ska.blogspot.com - Reggae and SKA Music Blog
----------------------------------------------------


--
To UNSUBSCRIBE, email to debian-arm-REQUEST@...
with a subject of "unsubscribe". Trouble? Contact listmaster@...


Re: Shell Script on Debian

by Lennart Sorensen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Jun 27, 2008 at 11:42:53AM +0200, Lo?c Minier wrote:
>  (Not quite sure how this relates to arm.)
>
> On Fri, Jun 27, 2008, ApOgEE wrote:
> > set password [lindex \$argv 1]
>
>  The command line might be visible by all users of the system, unless
>  you use some locked down kernel, so I wouldn't pass the password on the
>  command line.

The environment could be viewed too.  A pipe should be OK I think.
Tricky to do in bash, but something like perl should able to do it,
which is at least how the debian installer used to manage to set
passwords in base-config in the past.

--
Len Sorensen


--
To UNSUBSCRIBE, email to debian-arm-REQUEST@...
with a subject of "unsubscribe". Trouble? Contact listmaster@...


Re: Shell Script on Debian

by Daniel Kahn Gillmor-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri 2008-06-27 09:39:24 -0400, Lennart Sorensen wrote:

> The environment could be viewed too.  

How can the environment be viewed, other than by the same user?  On a
lenny/sid system, it looks to me like the environment is only visible
to the process owner:

[0 dkg@squeak ~]$ ls -la /proc/*/environ | cut -f1,3 -d\  | sort | uniq -c
      2 -r-------- chipcard
     57 -r-------- dkg
      1 -r-------- dnslog
      5 -r-------- postgres
     95 -r-------- root
      1 -r-------- wt215
[0 dkg@squeak ~]$ ls -la /proc/*/cmdline | cut -f1,3 -d\  | sort | uniq -c
      2 -r--r--r-- chipcard
     57 -r--r--r-- dkg
      1 -r--r--r-- dnslog
      5 -r--r--r-- postgres
     95 -r--r--r-- root
      1 -r--r--r-- wt215
[0 dkg@squeak ~]$

Is there some other way to get access to a process's environment for a
different user?

Sorry for continuing the off-topic thread,

      --dkg


attachment0 (842 bytes) Download Attachment
LightInTheBox - Buy quality products at wholesale price