Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How can I access remote server to echo my root password on screen and then read from stdin ,,, any clue or tips on that
echo password | ssh --stdin "root@192.168.19.19"
when I tried it local it give an error
[root@localhost ~]# echo password | ssh --stdin "root@192.168.19.19"
Pseudo-terminal will not be allocated because stdin is not a terminal.
root@192.168.19.19's password:
It is not possible. The main feature of the secure shell SSH is that the traffic is encrypted and give a password in clear text in the command line does not make sense. If you want a passwordless connection, you can use "Public Key Authentication". Use ssh-keygen to create your own private/public key pair and arrange things accordingly to the ssh versions installed on both the client and the server.
Just remember that commands (normally) are stored, so if you do something like that the root password will be stored in clear text in ~/.bash_history. That is a bad thing. The same applies to scripts with expect. The scripts are also stored in clear text.
The solution I would prefer is to make an expect script which take your password as a argument. Then you add your script to $HISTIGNORE. This is a colon-separated list of patterns that won't be stored in .bash_history. I wouldn't say it's a good solution, but it is a solution if you have to specify the login password from the command-line.
#!/usr/bin/expect -f
# Expect script to supply root/admin password for remote ssh server
# and execute command.
# This script needs three argument to(s) connect to remote server:
# password = Password of remote UNIX server, for root user.
# ipaddr = IP Addreess of remote UNIX server, no hostname
# scriptname = Path to remote script which will execute on remote server
# For example:
# ./sshlogin.exp password 192.168.1.11
# ------------------------------------------------------------------------
# Copyright (c) 2004 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# ----------------------------------------------------------------------
# set Variables
set password [lrange $argv 0 0]
set ipaddr [lrange $argv 1 1]
set arg1 [lrange $argv 3 3]
set timeout -1
# now connect to remote UNIX box (ipaddr)
spawn ssh root@$ipaddr
match_max 100000
# Look for passwod prompt
expect "*?assword:*"
# Send password aka $password
send -- "$password\r"
# send blank line (\r) to make sure we get back to gui
send -- "\r"
interact
Thanks Dinithion,
I know about all the facts and usages of "expect" this is quite good script but I have to check some long list parameter on remote server and I have remote server's root password but I dont have any permission to to add my rsa key on remote server, and I have to check 200 servers, so I wrote on script for that but the issue is only for password.
This script only working for single command if you used any option with command then it's hang.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.