How to skip fingerprint checking when "sudo ssh localhost"? - ssh

When first enter a sudo ssh localhost we always get a note like:
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:u0q6ow7gfu4IvqfGOytZB6MKjO479AUr9hulSqO/dy4.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
And I want to skip this step.
I have try follow(with sshpass):
ssh-keygen -t rsa -P '' -f ~/.ssh/deploy_rsa<<<y
cat ~/.ssh/deploy_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
sudo ssh-keyscan localhost>>~/.ssh/known_hosts
Well it seems just works in ssh localhost, but not in sudo ssh localhost.
So is there any reliable way to access my goal?

ssh -o StrictHostKeyChecking=no localhost
Or for something more permanent, create or modify your ~/.ssh/config with this:
Host localhost
StrictHostKeyChecking no
Also you should know that this process opens you up to MITM attacks (not on localhost obviously) and shouldn't be done on any important server.

Related

scp is still requesting password

I want to copy big files from one linux server(SLES11) to another(SunOS) via bash scripting. I dont want to have a password promt so I used ssh-keygen to generate key about this connection.These are the steps I followed:
ssh-keygen -t rsa -b 2048
ssh-copy-id -i /home/username/.ssh/id_rsa.pub swtrans#111.111.111.111
ssh -i id_rsa.pub swtrans#111.111.111.111
After this scp command still requests password.
I am not 'root' user in both servers.
I changed permissions to 700 to the .ssh directory and 640 to the file authorized_keys in the remote server.
ssh -i id_rsa.pub swtrans#111.111.111.111
The -i argument accepts the private key, not the public one. You should use
ssh -i id_rsa swtrans#111.111.111.111
If it will not help, please provide the errors you can see in the server log and in the client

Connect over SSH using a .pem file

I would like to know how to connect over SSH using a .pem file to any server.
Currently I'm executing the following command:
ssh user#mydomain.example
What option should I use?
Use the -i option:
ssh -i mykey.pem user#mydomain.example
As noted in this answer, this file needs to have correct permissions set. The ssh man page says:
SSH will simply ignore a private key file if it is accessible by others.
You can change the permissions with this command:
chmod go= mykey.pem
That is, set permissions for group and others equal to the empty list of permissions.
chmod 400 mykey.pem
ssh -i mykey.pem user#mydomain.example
Will connect you over SSH using a .pem file to any server.
For AWS if the user is ubuntu use the following to connect to remote server.
chmod 400 mykey.pem
ssh -i mykey.pem ubuntu#your-ip
To connect from Terminal to AWS AMI:
chmod 400 mykey.pem
ssh -i mykey.pem ec2-user#mydomain.example
You can connect to a AWS ec-2 instance using the following commands.
chmod 400 mykey.pem
ssh -i mykey.pem username#your-ip
by default the machine name usually be like ubuntu since usually ubuntu machine is used as a server so the following command will work in that case.
ssh -i mykey.pem ubuntu#your-ip
If you still got error messages like:
Received disconnect from 34.219.50.0 port 22:2: Too many authentication failures. Disconnected from 34.219.50.0 port 22
Edit your SSH config located at ~/.ssh/config and add new record at the end
Host mydomain.example
User ubuntu
IdentityFile /home/you/path-to-pem/key.pem
IdentitiesOnly yes
Call short command: ssh mydomain.example
what resolved it for me was to run: sudo chown $USER: {.pem_file}

SSH "Failed to add the host to the list of known hosts" Openshift

I tried to use ssh command to connect to another remote host.
ssh -p 21098 -i $OPENSHIFT_DATA_DIR/.ssh/host_key user#domain.com
The authenticity of host '[domain.com]:21098 ([124.219.148.93]:21098)' can't be established.
RSA key fingerprint is 12:15:79:55:c6:2a:66:1e:82:94:da:19:e1:ca:21:3d.
Are you sure you want to continue connecting (yes/no)?yes
Failed to add the host to the list of known hosts (/var/lib/openshift/541b685c5973cae7bbf006f4/.ssh/known_hosts).
Connection closed by 124.219.148.93
I suppose we do not have access to home/.ssh. So how to solve this problem?
One can pass options to SSH on command line, like this:
ssh -o UserKnownHostsFile=/tmp/known_host_file -p 21098 -i $OPENSHIFT_DATA_DIR/.ssh/host_key user#domain.com
Here is related answer: ssh use known_hosts other than $HOME/.ssh/known_hosts

Avoid to insert path of SSH key pair when connecting through passwordless login

I've set a passwordless connection through ssh using SSH key pair.
So if I run the command:
ssh -i /root/.ssh/root_master master#ip
I'm able to connect to master#ip without typing the pwd.
However I would like to connect without typing
-i /root/.ssh/root_master
but just typing
ssh master#ip
Can anyone help me?
localHost $ ssh remotePassword#remoteHostname
If you want to connect to remote server just by typing above command; you must create ssh trust between your local host and remote host.
Step 1: Create ssh setup on both the host. ( usually, .ssh directory is present at ~ directory )
Step 2: Generate RSA key pair on both the hosts. To generate RSA key pair
cd ~; mkdir -p .ssh; cd .ssh
ssh-keygen -t rsa -f "id_rsa" -N "\" -P "\"; chmod 400 id_rsa
touch authorized_keys; touch known_hosts
Step 3: Write id_rsa.pub file of local host to authorized_keys file of remote host and vice-versa (in case, you want to build both sides trust)
Step 4: Also make entry into known_hosts file or it will automatically create when you will connect for the first time.
This way you can create ssh trust between host and so make them passwordless.
Another way to do this is to usee new ssh module of perl.

Cmd syntax to remotely execute a command through SSH

I would like to start up an application server that resides on another linux machine in another network, so SSH is required. How can I do it? Something like this?:
ssh user#host password /home/user/server/bin/run.sh
?
You can generate a ssh public/private key pair using ssh-keygen command, and then append your public key to .ssh/authorized_keys file of target host, then you can omit the 'password' part above.
ssh-keygen -t rsa
scp .ssh/id_rsa.pub user#host:.ssh/authorized_keys
ssh user#host
chmod og-rw .ssh/authorized_keys
chmod a-x .ssh/authorized_keys
chmod 700 .ssh