包含标签 ssh 的文章

Python远程操作SSH

三方组件 paramiko 创建ssh 连接 1 2 3 4 5 6 7 8 9 10 11 12 13 def connect_ssh(host: str, port: int, username: str, password: str): ssh = paramiko.SSHClient() key = paramiko.AutoAddPolicy() ssh.set_missing_host_key_policy(key) ssh.connect(host, port, username, password, timeout=5) return ssh 执行命令 1 2 3 4 5 6 7 8 9 def execute(ssh: paramiko.SSHClient): stdin, stdout, stderr = ssh.exec_command('command') for line in stdout.readlines(): print(line) ……

阅读全文

git使用ssh自动替代https

在使用go mod的时候,并且在一些私有的仓库,例如公司的代码库中,经常会需要输入密码,我们可以现在公司的代码库中设置好ssh密钥 本地执行git命令: 1 2 3 4 5 git config --global url."git@github.com:".insteadOf "https://github.com/" git config --global url."git@git.company.com:".insteadOf "https://git.company.com/" company.com换成你自己公司的地址即可。 而对于 golang.org 上的代码,在这一阶段,会从 https://go.googlesource.com 获取代码,不过庆幸的是,这些代码都在 github 上有镜像,我们可以替换一下: 1 2 3 git config --global url."git@github.com:golang/".insteadOf "https://go.googlesource.com/" ……

阅读全文