LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-10-2017, 05:05 AM   #1
Ankushkalra
Member
 
Registered: Jan 2017
Posts: 48

Rep: Reputation: Disabled
Encrypt password in sshpass


Hi,

We have rhel 7.x in our environment. I have created some scripts using "sshpass" tool like daily health check script etc.

Sample script using sshpass

ssh_user=Userid
ssh_pass='PasswordinPlainText'

for i in `cat ip_c.txt`

do
{
echo "****************************************$i**************************************************";
sshpass -p $ssh_pass ssh -t $ssh_user@$i "sudo su -";
}
done


Issue is that all these script contains my password in plain text.

My Requirement is to provide encrypted password in these scripts instead of plain text.Is there a way???

Also if there isnt a way to encrypt password in script,kindly suggest some other way.

Please note: Passwordless SSH is not possible as it is against our security policy

Thanks
 
Old 08-10-2017, 05:13 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
One option is that you can use keys with strong passphrases and then load the keys into an agent for reuse later. That avoids the "passwordless" situation.
 
Old 08-10-2017, 05:21 AM   #3
Ankushkalra
Member
 
Registered: Jan 2017
Posts: 48

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
One option is that you can use keys with strong passphrases and then load the keys into an agent for reuse later. That avoids the "passwordless" situation.

Thanks for the quick reply!!!!


I didn;t get you.Kindly elaborate.
 
Old 08-10-2017, 05:33 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
You would generate SSH keys using ssh-keygen, preferably ed25519, and the put the public key onto the remote machine inside the appropriate authorized_keys file. Then when that is proven to work, password authentication can be fully disabled for the SSH daemon. There are very many tutorials and guides on how to do key-based authentication.

Then once you have the keys working, use an agent on the client system. Your desktop might load one for you, in which case you just need to load the key using ssh-add before launching your script.

See:

Code:
man ssh
man ssh-add
man ssh-agent
man ssh-keygen
If you do not have an agent available for use, then you can use ssh-agent to launch your shell, load the key, then launch your script.

Code:
ssh-agent /bin/bash
If you use a strong passphrase with the private keys, then they are protected by AES-128 encryption. During the authentication they never leave the client and are used instead to deal with encrypted messages between the server and the client to verify identity.

(By the way, I would be very surprised if any security policy allows password-based authentication instead of keys.)

Last edited by Turbocapitalist; 08-10-2017 at 05:39 AM. Reason: more precision in link
 
Old 08-11-2017, 02:34 AM   #5
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
If you establish the ssh session, the connection is encrypted, so nothing is passed as plaintext.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: sshpass command : Non-interactive Password Authentication with SSH LXer Syndicated Linux News 0 08-27-2013 03:40 PM
encrypt the password nagavinodh Linux - Security 4 03-15-2010 11:31 AM
crypt() perl function to encrypt Password in shell scripts or How Encrypt passwords ? balakrishnay Linux - General 13 01-14-2010 09:35 AM
LXer: sshpass - Non-interactive ssh password authentication LXer Syndicated Linux News 0 05-04-2008 04:50 PM
Encrypt a partition with a password ? Coume Linux - Security 1 04-26-2005 03:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration