设置秘钥
mkdir -p ~/.ssh
echo "公钥内容" > ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
sed -r -i '/RSAAuthentication/d' /etc/ssh/sshd_config
sed -r -i '/PubkeyAuthentication/d' /etc/ssh/sshd_config
sh -c "echo 'RSAAuthentication yes' >> /etc/ssh/sshd_config"
sh -c "echo 'PubkeyAuthentication yes' >> /etc/ssh/sshd_config"
service sshd restart
禁用密码登录
sed -r -i '/PasswordAuthentication/d' /etc/ssh/sshd_config
sh -c "echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config"
service sshd restart
修改端口(一键修改为 29032)
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak;
sed -r -i '/Port/d' /etc/ssh/sshd_config
sh -c "echo 'Port 29032' >> /etc/ssh/sshd_config"
service sshd restart
一键设置
mkdir -p ~/.ssh
echo "公钥内容" > ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
sed -r -i '/RSAAuthentication/d' /etc/ssh/sshd_config
sed -r -i '/PubkeyAuthentication/d' /etc/ssh/sshd_config
sh -c "echo 'RSAAuthentication yes' >> /etc/ssh/sshd_config"
sh -c "echo 'PubkeyAuthentication yes' >> /etc/ssh/sshd_config"
sed -r -i '/PasswordAuthentication/d' /etc/ssh/sshd_config
sh -c "echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak;
sed -r -i '/Port/d' /etc/ssh/sshd_config
sh -c "echo 'Port 29032' >> /etc/ssh/sshd_config"
service sshd restart