I have a shell script which contains following command to copy test.dat file from remote server to my current directory :
scp remote_user_id#remote_server_name:<filepath>/test.dat .
upon executing the script , It asks for password which I have to enter manually. I do not have access to install or use sshpass or expect or even setting up ssh. How can I pass this password in the shell script ?
Use public key authentication
-i identity_file
Selects the file from which the identity (private key) for public key authentication is read. This option is directly passed to ssh(1).
You could also use rsync. rsync has options like --password-file
Related
how to run commands like ftp or sftp or scp in background? Also how to setup password less connection for running these command?
Look for manual pages for scp or rsync, which both can do this job well, if not being forced you don't want to use sftp or even the non encrypted ftp file transfer!
something like the following, for example:
rsync [some other parameters] -e ssh SOURCE TARGET
Assuming these commands are coming from a bash script , you would need to make sure that the two (or more ) systems have ssh certificates generated that allow you to access said systems without providing a "password" per se.
Briefly, you could do it by running this command on one system:
ssh-keygen
following through, this will generate a key. Then run:
ssh-copy-id user#some-remote-system
to copy it to the remote system, which will allow passwordless access, enabling scripts to go about their business without stalling for password prompts.
I need to upload a file via FTP with shell script.
Can I interact with FTP from the script? My Script is at http://pastebin.com/A76fsaM3
cd MyLocalUploadDir
ftp
open ftp.server.com
myusername
mypassword
put LocalIteam.TXT
Will this work? Is there another way to interact with FTP from within a shell script? Any help is appreciated!
See http://www.tldp.org/HOWTO/FTP-3.html for information regarding interaction with FTP.
You need to use a here-doc. Otherwise, the lines after ftp will not be used as input to the program.
cd MyLocalUploadDir
ftp <<EOF
open ftp.server.com
myusername
mypassword
put LocalIteam.TXT
quit
EOF
You can also avoid putting your username and password in the script by using a .netrc file.
And instead of using the ftp program, you could use curl to do it in one line.
curl --upload-file MyLocalUploadDir/LocalIteam.TXT 'ftp://myusername:mypassword#ftp.server.com/'
You can also use the --netrc option to curl to tell it to get the username and password from the .netrc file.
I am using shell script to add some file to server. Is there any way to write a shell script that will execute one part on local computer and the other part when you're logged into that server?
For example, I want to log in, do something, add some file, and then I want to list everything on that server.
ssh something#something
I enter password
Then list files from server.
You can just add a command to end of the ssh command; for example:
ssh username#host ls
will run ls on the server, instead of giving you a login shell.
I am writing a bourne shell script for the openwrt firware where I want to copy my files from router to linux machine. when i do
scp /etc/clients.txt shah#192.168.1.2:/home/shah/
from inside the router's openwrt firmware, it asks me to give the password. I want to give this password from within the script because this file needs to be copied after every 2 seconds. How can I do this without using expect?
You can try to use sshpass tool but you will need to provide a password in clear text in your script. If that is not a problem you should use it.
sshpass -p 'password' scp /etc/clients.txt shah#192.168.1.2:/home/shah/
I want to login to remote computer using shell script through ssh, i want to pass username and password from text file. how to do that?
here is code what i have tried.
#!/bin/sh
#
username=user
ip=192.168.2.21
ssh $username#$ip < user.txt
You can't SSH in the method that you're referring to. You will want to use SSH keys which are created to help with what you're doing.
Also, avoid storing your password in a text file.