1、使用 ssh-keygen -t rsa 生成私钥和公钥
ssh-keygen -b 1024 -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_dsa): /home/user/.ssh/id_dsa Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/user/.ssh/id_rsa. Your public key has been saved in /home/user/.ssh/id_ras.pub.
2、密钥分发
把私钥放在自己的机器上的~/.ssh/目录下并保证访问权限是“-rw-------”(即600)。 再把生成的公钥放在要连接的远程主机的~/.ssh/目录下并改名为authorized_keys,并且保证文件除了属主外没有被人修改的权限。命令
cd ~/.sshssh-copy-id user@IP
or ssh-copy-id –i id_rsa.pub user@IP3、登录
ssh username@ip直接登录4、运行命令
ssh user@ip ./test.sh
普通用户ssh连接linux服务器是总是提示:
ulimit: open files: cannot modify limit: Operation not permitted
解决办法:
vi /etc/security/limits.conf添加:
* soft nofile 65535
* hard nofile 65535如果无法登录,
删除/home/user/.ssh/known_hosts文件再试