Sponsored Content
Top Forums UNIX for Dummies Questions & Answers SSH with a --password command line??? Post 302171696 by sysgate on Friday 29th of February 2008 07:57:44 AM
Old 02-29-2008
will this work ?

cat myssh.tcl
Code:
#!/usr/bin/expect

set timeout -1

if { $argc != 4 } {
    puts "Usage $argv0 host user pass command"
    exit 1
}

set host [lindex $argv 0]
set user [lindex $argv 1]
set pass [lindex $argv 2]
set command [lindex $argv 3]

spawn sftp -oStrictHostKeyChecking=no -oCheckHostIP=no $user@$host
expect *assword:

send "$pass\r"
expect sftp>

send "$command\r"
expect sftp>

send "exit\r"
expect eof

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do I get ssh to run a command in one line?

How would I combine something like: localserver# ssh remoteserver remoteserver# find blah blah blah into a one liner that would ssh to the remote server and run the find command, so I could put it in a script to automatically go out and run things on remote servers with out needed user... (2 Replies)
Discussion started by: LordJezo
2 Replies

2. UNIX for Advanced & Expert Users

How to use SFTP from command line without entering user and password

I would like to use SFTP from command line without entering userid and password. Here is what I have gathered and did. 1) Create a public and private key pair for the protocol you want to use. To create a key pair for use by SSH2, enter: ssh-keygen -t dsa I did that and got... (7 Replies)
Discussion started by: Hangman2
7 Replies

3. Shell Programming and Scripting

FTP command line username and password passing

Dear All, I am new to unix and I am trying to build a shell script which will connect to a different server by passing username and password from a file or command line but not manually... In short I dont want to connect to a diff server via ftp interactively. Any suggestion...looking... (8 Replies)
Discussion started by: Pratik4891
8 Replies

4. Shell Programming and Scripting

ssh command with password

hi: how can i use ssh with password in the command line . (4 Replies)
Discussion started by: rainboisterous
4 Replies

5. Shell Programming and Scripting

Script filling password from command line

I have this command that i am calling from php (exec()): openssl pkcs12 -export -in cert.pem -inkey key.pem -out cred.p12 and then i need to insert password twice Enter Export Password: Verifying - Enter Export Password: I need script that will fill the password... (3 Replies)
Discussion started by: rockyada
3 Replies

6. Shell Programming and Scripting

how to run a command line with another user without prompts for password

Hi, I'm writing a script, in the script I need to use tcpdump to capture some packets however it needs root priviledge my computer is configured by school and I have no real root priviledge so I can't use sudo on my computer,like Code: sudo tcpdump ...... I have to use a limited... (1 Reply)
Discussion started by: esolve
1 Replies

7. Shell Programming and Scripting

Passing password with SSH command

Hi Experts, I have specific requirement where I want to pass the password with the ssh username@hostname command . I dont want to use RSA public and private keys also. Because that will be on production server and no one wants to give access like that. Second thing it is production... (14 Replies)
Discussion started by: sharsour
14 Replies

8. UNIX for Dummies Questions & Answers

Ssh command without password - Not working

Hi, I have followed the below commands for key generation and ssh from one server to another with user mqm cd /var/mqm/.ssh mqm@A:~> ssh-keygen -t rsa <public key creation> mqm@A:~> ssh mqm@B mkdir -p .ssh mqm@B's password: <entered_password> mqm@A:~> cat /var/mqm/.ssh/id_rsa.pub | ssh... (4 Replies)
Discussion started by: Anusha M
4 Replies

9. Shell Programming and Scripting

Need one line command to create and set password for new user...

Using useradd abc --password password (5 Replies)
Discussion started by: Jagruti Rml
5 Replies

10. Shell Programming and Scripting

Ssh remote command and print same line

john-test:/root> ssh -q chicago-ser uname;date Linux Fri Oct 13 16:41:11 GMT 2017 How I can print on the same line like this : Linux Fri Oct 13 16:41:11 GMT 2017 (2 Replies)
Discussion started by: jhonnyrip
2 Replies
SSHPASS(1)							Sshpass User Manual							SSHPASS(1)

NAME
sshpass - noninteractive ssh password provider SYNOPSIS
sshpass [-ffilename|-dnum|-ppassword|-e] [options] command arguments DESCRIPTION
This manual page documents the sshpass command. sshpass is a utility designed for running ssh using the mode referred to as "keyboard-interactive" password authentication, but in non- interactive mode. ssh uses direct TTY access to make sure that the password is indeed issued by an interactive keyboard user. Sshpass runs ssh in a dedicated tty, fooling it into thinking it is getting the password from an interactive user. The command to run is specified after sshpass' own options. Typically it will be "ssh" with arguments, but it can just as well be any other command. The password prompt used by ssh is, however, currently hardcoded into sshpass. Options If no option is given, sshpass reads the password from the standard input. The user may give at most one alternative source for the pass- word: -ppassword The password is given on the command line. Please note the section titled "SECURITY CONSIDERATIONS". -ffilename The password is the first line of the file filename. -dnumber number is a file descriptor inherited by sshpass from the runner. The password is read from the open file descriptor. -e The password is taken from the environment variable "SSHPASS". SECURITY CONSIDERATIONS
First and foremost, users of sshpass should realize that ssh's insistance on only getting the password interactively is not without reason. It is close to impossible to securely store the password, and users of sshpass should consider whether ssh's public key authentication pro- vides the same end-user experience, while involving less hassle and being more secure. The -p option should be considered the least secure of all of sshpass's options. All system users can see the password in the command line with a simple "ps" command. Sshpass makes a minimal attempt to hide the password, but such attempts are doomed to create race conditions without actually solving the problem. Users of sshpass are encouraged to use one of the other password passing techniques, which are all more secure. In particular, people writing programs that are meant to communicate the password programatically are encouraged to use an anonymous pipe and pass the pipe's reading end to sshpass using the -d option. RETURN VALUES
As with any other program, sshpass returns 0 on success. In case of failure, the following return codes are used: 1 Invalid command line argument 2 Conflicting arguments given 3 General runtime error 4 Unrecognized response from ssh (parse error) 5 Invalid/incorrect password 6 Host public key is unknown. sshpass exits without confirming the new key. In addition, ssh might be complaining about a man in the middle attack. This complaint does not go to the tty. In other words, even with sshpass, the error message from ssh is printed to standard error. In such a case ssh's return code is reported back. This is typically an unimaginative (and non-informative) "255" for all error cases. EXAMPLES
Run rsync over SSH using password authentication, passing the password on the command line: rsync --rsh='sshpass -p 12345 ssh -l test' host.example.com:path . To do the same from a bourne shell script in a marginally less exposed way: SSHPASS=12345 rsync --rsh='sshpass -e ssh -l test' host.example.com:path . BUGS
Sshpass is in its infancy at the moment. As such, bugs are highly possible. In particular, if the password is read from stdin (no password option at all), it is possible that some of the input aimed to be passed to ssh will be read by sshpass and lost. Sshpass utilizes the pty(7) interface to control the TTY for ssh. This interface, at least on Linux, has a misfeature where if no slave file descriptors are open, the master pty returns EIO. This is the normal behavior, except a slave pty may be born at any point by a pro- gram opening /dev/tty. This makes it impossible to reliably wait for events without consuming 100% of the CPU. Over the various versions different approaches were attempted at solving this problem. Any given version of sshpass is released with the belief that it is working, but experience has shown that these things do, occasionally, break. This happened with OpenSSH version 5.6. As of this writing, it is believed that sshpass is, again, working properly. Lingnu Open Source Consulting August 6, 2011 SSHPASS(1)
All times are GMT -4. The time now is 03:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy