Skip to content

Instantly share code, notes, and snippets.

@CoderPiF
Last active July 6, 2017 10:35
Show Gist options
  • Save CoderPiF/14ae6e3fea7e2914679b3277c19cba4a to your computer and use it in GitHub Desktop.
Save CoderPiF/14ae6e3fea7e2914679b3277c19cba4a to your computer and use it in GitHub Desktop.
服务器屏蔽密码登录,开启钥匙串登录
#!/bin/bash
# Usage : curl -O https://gist.githubusercontent.com/CoderPiF/14ae6e3fea7e2914679b3277c19cba4a/raw/UsingRSAKeyLoginSSH.sh && sh UsingRSAKeyLoginSSH.sh
ConfigFile=/etc/ssh/sshd_config
cp ${ConfigFile} ${ConfigFile}.bak
sed -i -e '/RSAAuthentication/d' ${ConfigFile}
echo 'RSAAuthentication yes' >> ${ConfigFile}
sed -i -e '/PubkeyAuthentication/d' ${ConfigFile}
echo 'PubkeyAuthentication yes' >> ${ConfigFile}
sed -i -e '/AuthorizedKeysFile/d' ${ConfigFile}
echo 'AuthorizedKeysFile %h/.ssh/authorized_keys' >> ${ConfigFile}
sed -i -e '/PasswordAuthentication/d' ${ConfigFile}
echo 'PasswordAuthentication no' >> ${ConfigFile}
mkdir -p ~/.ssh
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCiQo2FkZkdP4Pki/TdvhriD2/Ts4AFzu5iHZInRCL3i86yMNWBxpG/ydcuD4bLyRY1WWrREJ4JMflwRrbMNmZPPg7B60xVloSj8142qxbNM+xy7lTTvwDahcfKzLCjjWWuUkgnXymU49U6JP0lURwdhLvRItkdOSLTHFy65vHmUe2CHLVZNulU+OdIGionDxQLLVrkxN2Uz6I7vmOl2JeycjRY+fTDLGdFJ7CekV55qubDXob3gh5Bs/Ex+34c3MfQq15a5xiON5NDBsBBjP9X7NLEcd5e2DwecCZwgkItwa+HTwf7UgOTHnRA5nPbvgS7Zp6girJqPM7clMV/326T' >> ~/.ssh/authorized_keys
/etc/init.d/ssh restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment