How to automatically enter username and password when prompted to connect to a remote server

echo Lee

I want to write a bash script to connect to my remote server and do some file transfer.

But because connection prompts for username and then hit enter, and then it requires the password.

How can I use the bash script to automatically enter these things?

For example echo username; | ssh [email protected] this does not work.

Terrance

One of the easiest ways would be to add your key to the remote host. To add your key to the remote host so that ssh / scp does not require a password you can run:

ssh-copy-id [email protected]

Then you can use scp to copy from the remote to the client system in the current folder you are in:

scp [email protected]:/path/to/file/filename .

Or copy it to any folder that you have write access to on your client host:

scp [email protected]:/path/to/file/filename /local/folder/to/store/in/

Another way to do it would be to install sshpass (sudo apt install sshpass) on your client system. Then you can use it to log into the remote host and run the commands that way. One thing to remember that storing a password in a script can be read by anyone that has access to the script.

To use sshpass see https://askubuntu.com/a/385850/231142

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to make python script press 'enter' when prompted on Shell

How do I provide a username and password when running "git clone [email protected]"?

How to connect to MongoDB 3.2 in Java with username and password?

How to connect to an ActiveMQ server by setting the username and password programmatically?

How to QUIETLY start Powershell.exe using different credentials (without getting prompted for username/password)?

How Can I Enter Username And Password Outputs To A MySQL Server Without Using POST or GET

Automatically do keypress enter when prompted in command prompt

No visible tags to enter username or password when scraping webpage

How to connect with an API that requires username and password

Use windows explorer to connect to a server with username and password

Server asks for Username and Password when Uploading File

How to automatically enter user password when prompted by terminal

Script to connect with ssh to remote server with password

How to change username in Connect to server?

FTP connect with no username and password?

How to connect mongodb(mongoose) with username and password?

How to change language automatically when prompted for a password?

How to connect LDAP With username and password?

How to enter network name and password to connect via ethernet in Ubuntu Server

How do I automatically fire a (remote) stored procedure in SQL Server when connecting to a remote server?

How to connect react with remote server

Client/Server app, how to create process on remote system as a domain user without transferring that users username/password to the remote system?

How to connect with coreNLP server with username password?

How to escape @ in password when doing ssh to remote server?

How to provide input to cmd automatically when prompted?

Why am I prompted for a password when using SSH to connect to another server?

How to paste a password in Remmina when connecting to a remote xrdp server

Connect to OPCUA server with username and password

How to "source ~/.bashrc" automatically when connect to remote