ssh user@地址 /bin/ls //类似给我返回ls命令的结果,而不登录远程服务器
类似linux里面 su 命令加-c参数,切换用户执行一条命令,而不用切换到那个用户去
用ssh命令 用户名@地址 密码 命令 ? //能实现吗?还是有别的命令?
ssh [email protected] 'command ...'
scp [email protected]:/remote/path /local/path
scp /local/path [email protected]:/remote/path
- X forward
ssh -X [email protected]
xcommand ...
- Tunnel / Portforward
ssh -L 1234:remote.machine:4321 [email protected]
ssh -R 1234:local.machine:4321 [email protected]
ssh -L 1234:other.machine:4321 [email protected]
# vi /etc/ssh/sshd_config
PermitRootLogin no
# vi /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no
# service sshd restart
# su - user1
$ mkdir ~/.ssh 2>/dev/null
$ chmod 700 ~/.ssh
$ touch ~/.ssh/authorized_keys
$ chmod 644 ~/.ssh/authorized_keys
登入 端:
$ ssh-keygen -t rsa
(按三下 enter 完成﹔不需设密码,除非您会用 ssh-agent 。)
$ scp ~/.ssh/id_rsa.pub [email protected]:id_rsa.pub
(若是 windows client, 可用 puttygen.exe 产生 public key,
然后复制到 server 端后修改之, 使其内容成为单一一行.)
回到 server 端:
$ cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
$ rm ~/id_rsa.pub
$ exit
# vi /etc/pam.d/su
auth required /lib/security/$ISA/pam_wheel.so use_uid
# visudo
%wheel ALL=(ALL) ALL
# gpasswd -a user1 wheel
# vi /etc/pam.d/sshd
auth required pam_listfile.so item=user sense=allow file=/etc/ssh_users ōnerr=fail
# echo user1 >> /etc/ssh_users