비밀번호없이 localhost에 ssh하는 방법은 무엇입니까?
편집 : 정확히 무엇을했는지
암호없이 로컬 호스트를 SSH해야합니다. 일반적인 방법 (공개 키 사용)이 작동하지 않습니다.
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:~$
따라서 마지막 명령에서 볼 수 있듯이 여전히 암호를 요구합니다! 어떻게 고칠 수 있습니까? Ubuntu-10.04, OpenSSH_5.3p1
EDIT2 :
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 : $ 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:
로그인이 적은 비밀번호를 만들기 위해 3 단계를 수행했습니다.
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
문제를 발견했습니다.
디버깅으로 서버 실행 :
$sshd -Dd
auth_key를 읽을 수 없음을 발견했습니다.
$chmod 750 $HOME
고쳤다.
또 다른 가능한 대답 : authorized_keys 파일이 존재하고 읽을 수 있습니다. 그러나 그룹 또는 모든 사람이 쓸 수있는 경우 암호를 입력하라는 메시지가 계속 표시됩니다. 그 문제에 대한 답은
chmod og-wx ~/.ssh/authorized_keys
다음 단계를 수행하십시오.
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
Two simple steps:
ssh-keygen -t rsa <Press enter for each line>
ssh-copy-id localhost
Enter password and you're done.
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
ReferenceURL : https://stackoverflow.com/questions/7439563/how-to-ssh-to-localhost-without-password
'IT박스' 카테고리의 다른 글
RegExp 개체에 정규식 수정 자 옵션 전달 (0) | 2020.12.29 |
---|---|
파일 크기 찾기 (0) | 2020.12.29 |
Total Commander에서 검색 할 때 .svn 폴더를 무시하는 방법 (0) | 2020.12.28 |
ActiveRecord Arel OR 조건 (0) | 2020.12.28 |
MongoDB 컬렉션의 하위 집합을 다른 컬렉션에 저장 (0) | 2020.12.28 |