Encyrpt does not work in bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Encyrpt does not work in bash script
# 1  
Old 09-01-2017
Encyrpt does not work in bash script

Hi All,

I am looking here from any one.

I am preparing script for create user and set password to remote servers.
I have made password less. and able to add user and also able to set entry in /etc/shadow. But it does not make complete entry in shadow file. it lefts initial character which are after $.

Code:
cat /etc/shadow file - output
  
 user1:jpKuSI11sl4wz2zJ6C3w6Qph2evoCqrO8SJjaz1Ux32kbPkMUxz8ppw7DcnyIeEqxhbb0GxsyCq18amHxL.zaxD1IZ1.:17408:0:99999:7:::

******************************
script......

Code:
#!/bin/bash
for i in `cat servername1`;
do
ssh -q -t root@$i sudo /usr/sbin/useradd -u 1001  -s /bin/bash -m -d /home/user1 -c 'for user1' -p $6$9jpKuSI1$91sl4wz2zJ6C3w6Qph2evoCqrO8SJjaz1Ux32kbPkMUxz8ppw7DcnyIeEqxhbb0GxsyCq18amHxL.zaxD1IZ1. user1
echo user1 created on server $i
 done

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 09-01-2017 at 05:35 AM.. Reason: Added CODE tags.
# 2  
Old 09-01-2017
You need to escape the leading $ character, or put the entire password in single quotes.
bash is eating the leading $. There used to be limits to the size of passwords, since you did not post the OS, I would guess you need to be careful of the number of characters.

FWIW: huge passwords invite users to write them down, which creates a security concern. Why? nobody can remember 40 random characters reliably. I do not know what you are trying to do, but this seems like a bad approach to me.
# 3  
Old 09-01-2017
I am using rhel 6.5.

And I used the encrypt password in the script. (usermod -p, useradd -p)

and I tried single and double quote also . but it is not working.

can you please help.
# 4  
Old 09-01-2017
Show what you tried.
# 5  
Old 09-02-2017
I tried to create user on remote and set password also.

Below is my script. it creates user but does not set password correctly in /etc/shadow.


Code:
 #!/bin/bash
for i in `cat servername1`;
do
ssh -q -t root@$i sudo /usr/sbin/useradd -u 1001  -s /bin/bash -m -d /home/user1 -c 'for user1' -p $6$9jpKuSI1$91sl4wz2zJ6C3w6Qph2evoCqrO8SJjaz1Ux32kbPkMUxz8ppw7DcnyIeEqxhbb0GxsyCq18amHxL.zaxD1IZ1. user1
echo user1 created on server $i
 done


Last edited by jim mcnamara; 09-02-2017 at 09:43 AM..
# 6  
Old 09-02-2017
Did you actually try (showing only the -p argument ) :
Code:
-p '$6$9jpKuSI1$91sl4wz2zJ6C3w6Qph2evoCqrO8SJjaz1Ux32kbPkMUxz8ppw7DcnyIeEqxhbb0GxsyCq18amHxL.zaxD1IZ1.'  

# or 

-p "\$6\$9jpKuSI1$91sl4wz2zJ6C3w6Qph2evoCqrO8SJjaz1Ux32kbPkMUxz8ppw7DcnyIeEqxhbb0GxsyCq18amHxL.zaxD1IZ1."

I am assuming the period characters are part of the value you want.

Also consider actually logging in to the remote. (I think you may have done this, but use the above syntax) Then try your command, do not issue a command from ssh. Why? The command on the remote will have had the ' or " characters stripped before processing. Whenever you have issues with a complex ssh command, make the actual command work locally first - or put it in a shell script, scp the script over to the remote, then activate the script with an ssh command. This has eliminated some issues for me in the past.

Last edited by jim mcnamara; 09-02-2017 at 09:56 AM..
# 7  
Old 09-03-2017
Jim, Thanks for your reply.

I have changed in the script, what you suggested. but in shadow file does not put password correctly. it left after dollar($) sign.
It works fine in command prompt.

Please find my script and running output.

Code:
[root@server-rhel6 ~]# cat adduser.sh
#!/bin/bash
for i in `cat servername1`;
do
ssh -q -t root@$i sudo /usr/sbin/useradd -u 1001 -s /bin/bash -m -d /home/testuser -c 'URid_testuser-p "\$6\$h8GQyPz4\$I1C.whHxlC65VYVfnEfSunDf8W.zTl3OtU2p6fULLG0S7JGMnfrvCytj3VGBsZ3gK./fUDTL.Vxxxd22u48St." testuser
echo testuser created on server $i
done

Running script with -x option-----

Code:
[root@server-rhel6 ~]# sh -x adduser.sh
++ cat servername1
+ for i in '`cat servername1`'
+ ssh -q -t root@node1-rhel6 sudo /usr/sbin/useradd -u 1001-p '$6$h8GQyPz4$I1C.whHxlC65VYVfnEfSunDf8W.zTl3OtU2p6fULLG0S7JGMnfrvCytj3VGBsZ3gK./fUDTL.Vxxxd22u48St.' testuser
+ echo testuser created on server node1-rhel6
testuser created on server node1-rhel6
+ for i in '`cat servername1`'
+ ssh -q -t root@node2-rhel6 sudo /usr/sbin/useradd -u 1001 -s /bin/bash -m -d /home/adubey01 -c URid_testuser -p '$6$h8GQyPz4$I1C.whHxlC65VYVfnEfSunDf8W.zTl3OtU2p6fULLG0S7JGMnfrvCytj3VGBsZ3gK./fUDTL.Vxxxd22u48St.' testuser
+ echo testuser created on server node2-rhel6
testuser created on server node2-rhel6
[root@server-rhel6 ~]#

Shadow file output-----

Code:
testuser:.whHxlC65VYVfnEfSunDf8W.zTl3OtU2p6fULLG0S7JGMnfrvCytj3VGBsZ3gK./fUDTL.Vxxxd22u48St.:17410:0:99999:7:::

Please suggest.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 09-03-2017 at 01:31 PM.. Reason: Added CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash script does not work as expected

Repeat this text in a file named notes.txt and run the script Before bash is a good language a blank line appears Also, the following notes are displayed incorrectly What is bad? ================================== Title : Note 1 ================================== Category: Computer Date... (3 Replies)
Discussion started by: cesar60
3 Replies

2. AIX

Bash does not work on AIX 7.2

We have a new LPAR with AIX 7.2. We want to work with bash, so installed bash from Perzl (bash_64-4.4.5.aix5.1.ppc.rpm). But after install bash does not work. If I call "bash", nothing happens. The xterm, where I started bash, is totally dead. I tried the bash from aixtools.net, too. Same... (4 Replies)
Discussion started by: BuSchu
4 Replies

3. Shell Programming and Scripting

Bash script: "mkdir -p" doesn't work with var(cat x)

Hello, :) I've an issue with the creation of a directory, All work without it :mad: So, below, my scripts with the debug output : #!/bin/bash # PATHS HOME_BACKUP="/home/backup" HOME_SCRIPT="/home/scripts/test/backup_server" TARGET="/var/www" # DATE DATE_Ymd=$(date +%Y-%m-%d) #... (1 Reply)
Discussion started by: Arnaudh78
1 Replies

4. Shell Programming and Scripting

Rsync in bash script doesn't work even after placing pub key in target server

Hello Friends, My bash script is like this #!/bin/bash # request Bourne shell as shell for job #$ -S /bin/bash # assume current working directory as paths #$ -cwd #$ -N rsync-copy # # print date and time date rsync -rltD --progress "ssh -i /home/myname/.ssh/id_rsa"... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

5. Shell Programming and Scripting

Nested double quotes won't work in my bash script?

In a bash script I have: LSCMD="find /project/media/ -mindepth 2 -maxdepth 2 -name \"files*pkg\"" ALL_PACKAGES=$( $LSCMD | sort 2>/dev/null) But I get nothing returned. It's just all blank. If I run the find command in a terminal, I get dozens of hits. I figure it's the way how I'm... (3 Replies)
Discussion started by: superbbrr
3 Replies

6. Shell Programming and Scripting

My script work on Linux but not work in sunos.

My script work on Linux but not work in sun os. my script. logFiles="sentLog1.log sentLog2.log" intial_time="0 0" logLocation="/usr/local/tomcat/logs/" sleepTime=600 failMessage=":: $(tput bold)Log not update$(tput rmso) = " successMessage="OK" arr=($logFiles)... (7 Replies)
Discussion started by: ooilinlove
7 Replies

7. Shell Programming and Scripting

pipe to grep doesn't work in bash script

Hi, I'm trying to write a script that checks gvfs to see if a mount exists so I can run it from network-manager's status hooks. I thought I'd pipe the output of gvfs-mount -l to grep for the particular mounts I care about. When I do this in a bash script: cmnd="gvfs-mount -l | grep -i... (4 Replies)
Discussion started by: kcstrom
4 Replies

8. Shell Programming and Scripting

cant get a counter to work in bash scipt, this is calling expect script

I have looked high and low, tryed lots of diffrent things but cant get a simple counter to work right. what i need is to increase a count ever time it finishes the test, pass or fail. example TEST PASS 1, NEXT TEST PASS 2, I curently have set foo o while {$foo <=5} { incr foo puts... (1 Reply)
Discussion started by: melvin
1 Replies

9. Shell Programming and Scripting

Open and work on a .doc file with bash script

Hello there....unix users :) I hope you can help me with this: I need open a doc file or xls files and work this files whit a bash script. For example: Open a doc file and copy information from a txt file in this doc file or xls file. Is it possible? Sorry for my english...I'm chilean... (3 Replies)
Discussion started by: bobbasystem
3 Replies

10. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies
Login or Register to Ask a Question