linux 禁用密码登录
Last updated on November 22, 2024 pm
🧙 Questions
使用密码登录服务器,容易被破解,禁止使用密码登录服务器
☄️ Ideas
开启密码禁用
vim /etc/ssh/sshd_config
配置禁止密码登录
PasswordAuthentication no
重启ssh服务
service sshd restart
配置公钥登录
服务器中生成ssh文件
# 一路回车
ssh-keygen
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
ssh-keyscan -H isxcode >> ~/.ssh/known_hosts
本地生成ssh文件,如果存在不需要再次生成
# 一路回车
ssh-keygen
cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCqo2iGsQ0mKTGVkMeFeNJZNbA+WYjYcC3h60o67IfdOyAcSwB3b94og6ApGWpcMMdFZYK/9vg425SFstuQjmXqGsLaa0g4WNnNqql4q9woHrapvjS2EgCwMoStolZmSZi3epq5Fr+PhH9fZ23jhggud2EUK1ozOcldHbxgeYjEIFDBK5BcOTE0e5gULyjjL7bplKR0WS9i03z1iVV/3fvQ0J+0IregU/FKE7EoXgYqVQXyG/hA93qESWtlLGr6o1JRCx3nSVL5/7tADwtJSs0t6XjYZaumb3SO5D2FpJ3akAoSiDzLKWvMfcnCWrVEeAMEb1UXrXxI+S74wVJZEx+99vZMp8VZXembDDGQcT0TAXScxWihfYvgntJpTwTX2k40EjFo0VYO2aR6GIITdXFOvtJL66oFI+sV7G0WgGm0WY77vZfyNMVbBzTKxJhSLyr7B1Z7WRhhdOIWluybtA6SPaWCBwLHkEQRGoWKir/MjWbCIwcqG9uinyUJXmkwZ6c= ispong@ispong-mac.local
将本地的公钥复制到服务器中的
authorized_keys
文件中
tee -a ~/.ssh/authorized_keys <<-'EOF'
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCqo2iGsQ0mKTGVkMeFeNJZNbA+WYjYcC3h60o67IfdOyAcSwB3b94og6ApGWpcMMdFZYK/9vg425SFstuQjmXqGsLaa0g4WNnNqql4q9woHrapvjS2EgCwMoStolZmSZi3epq5Fr+PhH9fZ23jhggud2EUK1ozOcldHbxgeYjEIFDBK5BcOTE0e5gULyjjL7bplKR0WS9i03z1iVV/3fvQ0J+0IregU/FKE7EoXgYqVQXyG/hA93qESWtlLGr6o1JRCx3nSVL5/7tADwtJSs0t6XjYZaumb3SO5D2FpJ3akAoSiDzLKWvMfcnCWrVEeAMEb1UXrXxI+S74wVJZEx+99vZMp8VZXembDDGQcT0TAXScxWihfYvgntJpTwTX2k40EjFo0VYO2aR6GIITdXFOvtJL66oFI+sV7G0WgGm0WY77vZfyNMVbBzTKxJhSLyr7B1Z7WRhhdOIWluybtA6SPaWCBwLHkEQRGoWKir/MjWbCIwcqG9uinyUJXmkwZ6c= ispong@ispong-mac.local
EOF
即可从本地访问服务器!!!
openssh密钥 转 rsa密钥
ssh-keygen -p -m PEM -f id_rsa
🔗 Links
linux 禁用密码登录
https://ispong.isxcode.com/os/linux/linux 禁用密码登录/