How to ssh to localhost without password? - networking
EDIT: Putting exactly what was done
I need to SSH localhost without password, the usual way of doing it (with public keys) do not work.
user#PC:~$ rm -rf .ssh/*
user#PC:~$ ssh-keygen -t rsa > /dev/null
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
user#PC:~$ ls .ssh/
id_rsa id_rsa.pub
user#PC:~$ ssh-copy-id -i localhost
The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is f7:87:b5:4e:31:a1:72:11:8e:5f:d2:61:bd:b3:40:1a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
user#localhost's password:
Now try logging into the machine, with "ssh 'localhost'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
user#PC:~$ ssh-agent $SHELL
user#PC:~$ ssh-add -L
The agent has no identities.
user#PC:~$ ssh-add
Identity added: /home/user/.ssh/id_rsa (/home/user/.ssh/id_rsa)
user#PC:~$ ssh-add -L
ssh-rsa ...MY KEY HERE
user#PC:~$ ssh-copy-id -i localhost
user#localhost's password:
Now try logging into the machine, with "ssh 'localhost'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
user#PC:~$ ssh localhost echo 'testing'
user#localhost's password:
user#PC:~$
So as you can see in the last command it is still asking the password!
How can I fix that? Ubuntu-10.04, OpenSSH_5.3p1
EDIT2:
Adding some info about the sshd
user#PC:~$ cat /etc/ssh/sshd_config | grep Authentication
# Authentication:
RSAAuthentication yes
PubkeyAuthentication yes
RhostsRSAAuthentication no
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
ChallengeResponseAuthentication no
# PasswordAuthentication yes
EDIT3: Ading result from $ssh -vv localhost
$ssh -vv localhost
...
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/user/.ssh/identity
debug1: Offering public key: /home/user/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/user/.ssh/id_dsa
debug2: we did not send a packet, disable method
debug1: Next authentication method: password
user#localhost's password:
I did following 3 steps to create the password less login
1. ssh-keygen -t rsa
Press enter for each line
2. cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
3. chmod og-wx ~/.ssh/authorized_keys
Have discovered the problem.
Running the server with debuging:
$sshd -Dd
I found it was not able to read the auth_key
$chmod 750 $HOME
Fixed it.
Another possible answer: the authorized_keys file may exist and be readable. But if it is group- or world-writable, it will still prompt for the password. The answer to THAT problem is
chmod og-wx ~/.ssh/authorized_keys
Two simple steps:
ssh-keygen -t rsa <Press enter for each line>
ssh-copy-id localhost
Enter password and you're done.
Do the following steps
ssh-keygen -t rsa -C "your_email#example.com"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
Use the default file and empty passphrase (Simply press enter in the next 2 steps)
# start the ssh-agent in the background
eval "$(ssh-agent -s)"
# Agent pid 59566
ssh-add
Copy the contents of ~/.ssh/id_rsa.pub to ~/.ssh/authorized_keys
Ensure following are the permissions
ls -l .ssh/
total 20
-rw-r--r--. 1 swati swati 399 May 5 14:53 authorized_keys
-rw-r--r--. 1 swati swati 761 Jan 12 15:59 config
-rw-------. 1 swati swati 1671 Jan 12 15:44 id_rsa
-rw-r--r--. 1 swati swati 399 Jan 12 15:44 id_rsa.pub
-rw-r--r--. 1 swati swati 410 Jan 12 15:46 known_hosts
Also, ensure the permissions for .ssh directory are. This is also important
drwx------. 2 swati swati 4096 May 5 14:56 .ssh
The correct and safe way of doing it is to copy the keys as has been said here.
In other cases, sshpass can be handy.
sshpass -p raspberry ssh pi#192.168.0.145
Keep in mind that this is not safe at all. Even though it is not a good idea to use it in secure environments, it can be useful for scripting, automated testing...
this can be combined with
ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no pi#192.168.0.145
to avoid confirmation questions that prevent scripting from happening.
Again, only use this in development systems where different machines share an IP and security is not important.
https://ownyourbits.com/2017/02/22/easy-passwordless-ssh-with-sshh/
as the accepted answer do,
if you encount a problem of
Agent admitted failure to sign using the key.
you need to
ssh-add
I faced the same issue even after following all the recommendations, but found out that the issue was with gnome-keyring interference.
Solution:
Go Search , look for “Startup Applications”
If you see “SSH Key Agent”, uncheck the box
Reboot the machine and connect to localhost.
I solved ssh login problem this way.
I generate the key pairs on my server side and then scp back the private key to my windows 10 computer and now I can login without password.
Previously I used key pairs generated by my window 10 laptop and there was no luck at all.
On Centos 7
SOLUTION
1 create rsa key
2 vim /etc/ssh/ssh_config
3
# IdentityFile ~/.ssh/identity
uncoment this line > IdentityFile ~/.ssh/id_rsa
# IdentityFile ~/.ssh/id_dsa
# IdentityFile ~/.ssh/id_ecdsa
Note *I did this after copying the key and some of the other answers before this one. But I am pretty sure this is all you have to do but if not I would append the rsa key to authorized_keys and also run the
ssh-copy-id to username#localhost
I encountered the same problem when running unit tests on Docker container(golang:1.13-alpine).
After sshd -Dd and ssh -vv root#localhost debugging, I found the reason:
User root not allowed because account is locked
So, we should unlock the account by passwd -u
or set a password.
I fixed my problem setting the AllowUsers on sshd_config file.
Running the server with debuging:
$sshd -Dd
I found it was not allowed the my user
$sudo vi /etc/ssh/sshd_config
Add a row with after #Authentication:
AllowUsers myUser
One thing to doublecheck if you have a known good configuration for ssh is that your /etc/hosts.allow includes a reference to localhost, since the source IP for a localhost connection would be coming from 127.0.0.1 rather than your network IP. I was stumped on this for some time, but after adding the following to /etc/hosts.allow my configuration immediately worked.
ALL: 127.0.0.1/32
I figured I would add this since none of the other answers mentioned it and this was the top hit from my search for the same error.
RHEL8
In my case after successful keys configuration it still did not work. I found following error in /var/log/secure:
pam_access(sshd:account): access denied for user `username' from `::1'
So I had to edit:
/etc/security/access.conf
And add there '::1' to allowed hosts by adding a line:
+:<username>:LOCAL ::1
It immediately started to work, even without restart of sshd service.
Related
Trying to scp to an EC2 instance, states sftp only?
scp -Cpv -i /home/jamie/Downloads/jamie1.pem /srv/http/wordpress/wp- content/themes/dt-the7 ec2-user#52.210.108.143:/var/www/html/wp-content/themes/ [...] debug1: Entering interactive session. debug1: pledge: network debug1: Sending command: scp -v -p -t /var/www/html/wp-content/themes/ This service allows sftp connections only. Can anyone tell me how to also allow ssh/scp connections? Thanks
You need to modify sshd_config on the server and restart the sshd daemon. The configuration will probably contain something like ForceCommand internal-sftp if you will comment that out, you should be able to get ssh and scp access.
Need to Run batch script in UNIX server and display the output through vbscript
I am currently developing the new VBScript to execute the Shell (through Putty software) in UNIX server, Set shell = WScript.CreateObject("WScript.Shell") shell.Exec D:\Putty.exe hostname -l username -pw password 1.sh I am getting connection refused error. when I run the below command without my script (1.sh) shell.Exec D:\Putty.exe hostname -l username -pw password Connection is getting established without any issues. Also, I just wanted to extract the output, once extracted, the session should get closed automatically.
This doesn't work in putty.exe. Putty has however a dedicated program to do these kind of things, it's called plink.exe - there you can pass commands and read the output just as you would expect, and your example should work just like you specified it. PuTTY Link: command-line connection utility Release 0.63 Usage: plink [options] [user#]host [command] ("host" can also be a PuTTY saved session name) Options: -V print version information and exit -pgpfp print PGP key fingerprints and exit -v show verbose messages -load sessname Load settings from saved session -ssh -telnet -rlogin -raw -serial force use of a particular protocol -P port connect to specified port -l user connect with specified username -batch disable all interactive prompts The following options only apply to SSH connections: -pw passw login with specified password -D [listen-IP:]listen-port Dynamic SOCKS-based port forwarding -L [listen-IP:]listen-port:host:port Forward local port to remote address -R [listen-IP:]listen-port:host:port Forward remote port to local address -X -x enable / disable X11 forwarding -A -a enable / disable agent forwarding -t -T enable / disable pty allocation -1 -2 force use of particular protocol version -4 -6 force use of IPv4 or IPv6 -C enable compression -i key private key file for authentication -noagent disable use of Pageant -agent enable use of Pageant -m file read remote command(s) from file -s remote command is an SSH subsystem (SSH-2 only) -N don't start a shell/command (SSH-2 only) -nc host:port open tunnel in place of session (SSH-2 only) -sercfg configuration-string (e.g. 19200,8,n,1,X) Specify the serial configuration (serial only)
SSH AUTHENTIFACTION ISSUE
I am a newbie to embedded networking. I want to set arm board as a ssh server .From other boards(client boards connected in the network), I need to connect to this server board. I have downloaded the openssh and cross compiled it for arm successfully. I have used default sshd_config file and run sshd command in arm-board. Command "ssh-keygen -t rsa -f /usr/local/etc/ssh_host_rsa_key -N "" " is used to genrate key. My doubt is where can I set the username and password, so that I can login from a remote client using ssh command. I didn't find any document regarding this...?
Using ssh you are logging in as a normal system user. So you should add user using useradd command. You can change password using passwd command.
Permission denied to use sftp -b batch file
I can log in to my remote using ssh/sftp (without the -b option) sftp root#192.168.7.2 But when I try sftp -b commands.tmp root#192.168.7.2 I get Permission denied (publickey,password). Couldn't read packet: Connection reset by peer Commands.tmp looks like this ls exit Anything I am missing here ?
I used shhpass to write the password no interactive and I needed to add -oBatchMode=no sshpass -p PASSWORD sftp -v -oBatchMode=no -b FILE USER#SERVER
If you are authentication with a password or an encrypted private key, you cannot use the -b with plain sftp. The sftp man says: Since it lacks user interaction it should be used in conjunction with non-interactive authentication You can for example use a passphrase-less private key together with the -b. If you want to use password authentication, you need to use workarounds like sshpass. See: How to run the sftp command with a password from Bash script?
This worked for me sshpass -p 'PASSWORDSTRING' sftp -v -oBatchMode=no -b deploy/production username#ipaddress production file put -rp /from-directory /to-directory
How do I remove the passphrase for the SSH key without having to create a new key?
I set a passphrase when creating a new SSH key on my laptop. But, as I realise now, this is quite painful when you are trying to commit (Git and SVN) to a remote location over SSH many times in an hour. One way I can think of is, delete my SSH keys and create new. Is there a way to remove the passphrase, while still keeping the same keys?
Short answer: $ ssh-keygen -p This will then prompt you to enter the keyfile location, the old passphrase, and the new passphrase (which can be left blank to have no passphrase). If you would like to do it all on one line without prompts do: $ ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile] Important: Beware that when executing commands they will typically be logged in your ~/.bash_history file (or similar) in plain text including all arguments provided (i.e. the passphrases in this case). It is, therefore, is recommended that you use the first option unless you have a specific reason to do otherwise. Notice though that you can still use -f keyfile without having to specify -P nor -N, and that the keyfile defaults to ~/.ssh/id_rsa, so in many cases, it's not even needed. You might want to consider using ssh-agent, which can cache the passphrase for a time. The latest versions of gpg-agent also support the protocol that is used by ssh-agent.
$ ssh-keygen -p worked for me Opened git bash. Pasted : $ ssh-keygen -p Hit enter for default location. Enter old passphrase Enter new passphrase - BLANK Confirm new passphrase - BLANK BOOM the pain of entering passphrase for git push was gone. Thanks!
You might want to add the following to your .bash_profile (or equivalent), which starts ssh-agent on login. if [ -f ~/.agent.env ] ; then . ~/.agent.env > /dev/null if ! kill -0 $SSH_AGENT_PID > /dev/null 2>&1; then echo "Stale agent file found. Spawning new agent… " eval `ssh-agent | tee ~/.agent.env` ssh-add fi else echo "Starting ssh-agent" eval `ssh-agent | tee ~/.agent.env` ssh-add fi On some Linux distros (Ubuntu, Debian) you can use: ssh-copy-id -i ~/.ssh/id_dsa.pub username#host This will copy the generated id to a remote machine and add it to the remote keychain. You can read more here and here.
To change or remove the passphrase, I often find it simplest to pass in only the p and f flags, then let the system prompt me to supply the passphrases: ssh-keygen -p -f <name-of-private-key> For instance: ssh-keygen -p -f id_rsa Enter an empty password if you want to remove the passphrase. A sample run to remove or change a password looks something like this: ssh-keygen -p -f id_rsa Enter old passphrase: Key has comment 'bcuser#pl1909' Enter new passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved with the new passphrase. When adding a passphrase to a key that has no passphrase, the run looks something like this: ssh-keygen -p -f id_rsa Key has comment 'charlie#elf-path' Enter new passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved with the new passphrase.
On the Mac you can store the passphrase for your private ssh key in your Keychain, which makes the use of it transparent. If you're logged in, it is available, when you are logged out your root user cannot use it. Removing the passphrase is a bad idea because anyone with the file can use it. ssh-keygen -K Add this to ~/.ssh/config UseKeychain yes
On windows, you can use PuttyGen to load the private key file, remove the passphrase and then overwrite the existing private key file.
In windows for me it kept saying "id_ed25135: No such file or directory" upon entering above commands. So I went to the folder, copied the path within folder explorer and added "\id_ed25135" at the end. This is what I ended up typing and worked: ssh-keygen -p -f C:\Users\john\.ssh\id_ed25135 This worked. Because for some reason, in Cmder the default path was something like this C:\Users\capit/.ssh/id_ed25135 (some were backslashes: "\" and some were forward slashes: "/")
If you have set a passphrase before and is using mac, use the keychain instead, you'll need to enter your passpharase for the last time and that's it ssh-add --apple-use-keychain ~/.ssh/id_rsa Enter passphrase for /Users/{{user_name}}/.ssh/id_rsa: Identity added: /Users/{{user_name}}/.ssh/id_rsa(/Users/{{user_name}}/.ssh/id_rsa)
If you are using Mac Go to .ssh folder update config file by adding "UseKeychain yes"