全球主机交流论坛

标题: 在VPS上如何SSH到另外一台VPS,端口非22 [打印本页]

作者: house    时间: 2012-4-26 12:49
标题: 在VPS上如何SSH到另外一台VPS,端口非22
[root@**~]# ssh root@IP:222
ssh: IP:222: Name or service not known
[root@**~]# ssh root@IP
ssh: connect to host IP port 22: Connection refused

另一台已改默认端口了,root@IP后面怎么加端口
作者: shineme    时间: 2012-4-26 12:50
ssh ip:端口

吧估计
作者: 小夜    时间: 2012-4-26 12:51
ssh -l root 12.3.4.5 -p 22333
作者: fatppmm    时间: 2012-4-26 12:52
提示: 作者被禁止或删除 内容自动屏蔽
作者: house    时间: 2012-4-26 13:02
小夜 发表于 2012-4-26 12:51
ssh -l root 12.3.4.5 -p 22333

小夜,能不能在这条命令加上密码,不用回车后再输入密码
作者: larry    时间: 2012-4-26 13:53
house 发表于 2012-4-26 13:02
小夜,能不能在这条命令加上密码,不用回车后再输入密码

只有密钥认证才能不输密码
作者: jumpsky    时间: 2012-4-26 14:02
还是小夜牛逼啊
作者: msg7086    时间: 2012-4-26 14:26
其实man一下不就有说明书了……
作者: my6360    时间: 2012-4-26 14:30
本帖最后由 my6360 于 2012-4-26 17:38 编辑

ssh命令不能带密码的,但你可以expect自动输入密码

例如把下面代码保持成一个gotoshh.sh
#!/usr/bin/expect
set pw 替换成密码
spawn ssh -fND 7076 替换成用户名@替换成vps的IP
expect 'password: '
send "$pw\r"
expect '#'
send "exit\r"
expect eof

再赋权chmod +x 777 gotoshh.sh

以后执行gotoshh.sh就自动实现密码输入了。
作者: qdmz    时间: 2012-4-26 14:41
提示: 作者被禁止或删除 内容自动屏蔽
作者: sunsea    时间: 2012-4-26 15:01
my6360 发表于 2012-4-26 14:30
ssh命令不能带密码的,但你可以expect自动输入密码

例如把下面代码保持成一个gotoshh.sh

set pw 替换成密码
这一句是后面跟密码还是pw换成密码
作者: sunsea    时间: 2012-4-26 15:18
larry 发表于 2012-4-26 13:53
只有密钥认证才能不输密码

centos下怎么用密钥自动登陆?求方法
作者: loveminds    时间: 2012-4-26 15:34
sunsea 发表于 2012-4-26 15:01
set pw 替换成密码
这一句是后面跟密码还是pw换成密码

pw后跟密码
作者: sunsea    时间: 2012-4-26 16:02
loveminds 发表于 2012-4-26 15:34
pw后跟密码

这个脚本可以加到rc.loacal里面做开机启动的吧?
占资源吗?
作者: loveminds    时间: 2012-4-26 16:06
sunsea 发表于 2012-4-26 16:02
这个脚本可以加到rc.loacal里面做开机启动的吧?
占资源吗?

脚本只是完成一次登录
作者: wst321    时间: 2012-4-26 16:14

作者: zc035    时间: 2012-4-26 16:18
建议不要使用密码验证的方式登录ssh 。不然整天扫描。
作者: sunsea    时间: 2012-4-26 16:26
my6360 发表于 2012-4-26 14:30
ssh命令不能带密码的,但你可以expect自动输入密码

例如把下面代码保持成一个gotoshh.sh

出问题了加权限提示
chmod: cannot access `777': No such file or directory
然后执行的时候提示
autossh.sh: line 3: spawn: command not found
couldn't read file "password: ": no such file or directory
autossh.sh: line 5: send: command not found
couldn't read file "#": no such file or directory
autossh.sh: line 7: send: command not found
couldn't read file "eof": no such file or directory
但是我expect装了
[root@nhd2 ~]# whereis expect
expect: /usr/bin/expect /usr/lib/expect5.43 /usr/share/man/man1/expect.1.gz
求指导这是咋回事?

作者: my6360    时间: 2012-4-26 17:40
sunsea 发表于 2012-4-26 16:26
出问题了加权限提示
chmod: cannot access `777': No such file or directory
然后执行的时候提示

你也不给我加点分,不理你鸟
作者: my6360    时间: 2012-4-28 16:04
sunsea 发表于 2012-4-26 16:26
出问题了加权限提示
chmod: cannot access `777': No such file or directory
然后执行的时候提示

你先看看gotoshh.sh这个文件生成了没有,感觉你连文件都没有生成成功,否则怎么会“chmod: cannot access `777': No such file or directory”呢
作者: sunsea    时间: 2012-4-28 16:11
my6360 发表于 2012-4-28 16:04
你先看看gotoshh.sh这个文件生成了没有,感觉你连文件都没有生成成功,否则怎么会“chmod: cannot access ...

有的,现在已经搞定了,没有用脚本,用pubkey做的
一条命令,哈哈




欢迎光临 全球主机交流论坛 (https://hostloc.9hanju.com/) Powered by Discuz! X3.4