-3

Every time I try to connect my Linux server via SSH, it asks me for my password. I’m using Ubuntu server 18.04

How do I do something to get the system to remember the password or just be in line of an Bash script to connect to the server server?

example of what happens to me:

ssh root@$ip
root@xxx.xxx.xxx.xxx's password: 

I did everything to don’t ask me again for password, but I failed.

I’m already using a Bash script like this:

echo PASSWORD
ssh root@xxx.xxx.xxx.xxx

Then I copy and paste password into password field. But this doesn’t work.

Giacomo1968
  • 55,001
  • Why not use SSH keys? Look at this answer: https://superuser.com/a/8110/167207 – Giacomo1968 Oct 30 '20 at 03:25
  • sorry i cant use ssh keys – Ali emaditaj Oct 30 '20 at 03:26
  • i have many ssh servers and i connect them in multiple times , doing that with jeys is too hard – Ali emaditaj Oct 30 '20 at 03:27
  • for the link you send , i recive: root@localhost:~# sshpass

    Command 'sshpass' not found, but can be installed with:

    apt install sshpass

    root@localhost:~# apt install sshpass Reading package lists... Done Building dependency tree
    Reading state information... Done E: Unable to locate package sshpass

    – Ali emaditaj Oct 30 '20 at 03:28
  • “i have many ssh servers and i connect them in multiple times , doing that with jeys is too hard.” Makes utterly no sense. I manage dozens of servers and using SSH keys is the simplest way to deal with stuff like this. – Giacomo1968 Oct 30 '20 at 03:40
  • If you need to login without keys but have a password, sshpass is the solution. Figure out how to get it installed on your system and you are solid. – Giacomo1968 Oct 30 '20 at 03:51
  • i just compiled https://github.com/bauruine/sshpass un my server , ts okay now , how ever , thanks – Ali emaditaj Oct 30 '20 at 03:55

1 Answers1

1

Personally I'd use key based login but if you really want to load a password into a script you can do something like create a file in your home folder, change the permissions so only you can read it. This file would have just the password in it, nothing else. Call the file as an example .password.

#!/bin/bash
password=$(<.password)

The password is now loaded into a variable use that in your script at the point you'll be inputting the password.

But really, use key based login and disable password.

boots
  • 31
  • oh man , i need to enter sopmething then , i need an automated script – Ali emaditaj Oct 30 '20 at 03:42
  • @Aliemaditaj Sorry, we are attempting to help you. But when you say in this comment, “i have many ssh servers and i connect them in multiple times , doing that with jeys is too hard.” that makes utterly no sense whatsoever. If you manage servers the desire is to always have SSH keys in place. – Giacomo1968 Oct 30 '20 at 03:44