Linux SSH 命令
ssh
ssh user@server
ssh-keygen
To create a new, 2048 bit RSA key. run the following
ssh-keygen -t rsa -b 2048
ssh-agent
运行时会自动 fork 它自身,然收打印出其所需的环境变量。
ssh-agent命令是一种控制用来保存公钥身份验证所使用的私钥的程序,其实就是一个密钥管理器
$ ssh-agent
setenv SSH_AUTH_SOCK /tmp/ssh-hvSvA15772/agent.15772;
setenv SSH_AGENT_PID 15778;
echo Agent pid 15778;
ssh-add
ssh-add命令是把专用密钥添加到ssh-agent的高速缓存中
Once you have uploaded your key, ensure that you are running an ssh-agent in your current shell/session, and add your key to it. This will allow the Git ssh tunnel to authenticate without any password prompts:
[ -z "$SSH_AUTH_SOCK" ] && eval `ssh-agent -s` && ssh-add
ssh-add 这个命令不是用来永久性的记住你所使用的私钥的。实际上,它的作用只是把你指定的私钥添加到 ssh-agent 所管理的一个 session 当中。而 ssh-agent 是一个用于存储私钥的临时性的 session 服务,也就是说当你重启之后,ssh-agent 服务也就重置了。
ssh-copy-id
把本地主机的公钥复制到远程主机的authorized_keys文件上
ssh-copy-id user@server
ssh-copy-id -i ~/.ssh/id_rsa.pub user@server
当然也可以不常用命令,直接cp本地的id_rsa.pub的内容到远程主机的~/.ssh/authorized_keys里
tips
To connect remote server by ssh user@server and ssh-copy-id to avoid input password
examples
- ssh远程执行commands, 并可以指定远程执行的shell, 如'/bin/bash'
ssh -tt $USER@$RUNNING_HOST '/bin/bash' <<EOF
...linux commands ...
exit
EOF
- 将要执行的命令写入cmd.txt文件中
ssh -tt $SSH_CONNECTIOIN '/bin/bash' < /scratch/cmd.txt
- ssh执行sqlpus
ssh -tt $user@$hostname '/bin/bash' <<EOF
export ORACLE_HOME=$ORACLE_HOME
export ORACLE_SID=$ORACLE_SID
$ORACLE_HOME/bin/sqlplus -S "fusion/fusion" >/scratch/$user/$tableName <<eof
set pagesize 0
select NLS_INITCAP (TABLE_NAME) from user_tab_comments where TABLE_NAME like 'PEOPLE%';
exit;
eof
$ORACLE_HOME/bin/sqlplus -S "fusion/fusion" <<eof
set serveroutput on
grant SELECT ANY SEQUENCE, CREATE ANY SEQUENCE to FUSION_APPS_READ_AND_WRITE;
BEGIN
FOR item IN (select table_name from user_tab_comments where TABLE_NAME like 'PEOPLE%' or TABLE_NAME like 'PERFORMANCE%') LOOP
DBMS_OUTPUT.PUT_LINE('grant select,update,insert,delete ON '||item.table_name);
EXECUTE IMMEDIATE 'GRANT SELECT,update,insert,delete ON ' || item.table_name || ' TO FUSION_APPS_READ_AND_WRITE';
END LOOP;
END;
/
exit;
eof
exit
EOF